

``` r
#INTRO: LOADING PACKAGES ETC----
library(foreign)
library(reshape2)
library(data.table)
library(stargazer)
library(MatchIt)
#library(nonrandom)
library(ggplot2)
#library(gdata1)
library(gmodels)
library(gridExtra)
library(haven)
library(plyr)
#library(car)
#library(xlsx)
library(tidyr)
library(reshape)
library(countrycode)
#library(dGlyr)
library(readr)
library(gnm)
library(MNP)
library(nls2)
library(nlstools)
library(stats)
library(dplyr)
library(matrixStats)
library(miceadds)
library(minpack.lm)
library(lfe)
library(lubridate)
library(AER)
library(reshape)
library(reshape2)
library(tictoc)
library(xtable)
library(Formula)
library(mlogit)
library(plm)
library(survival)
library(plotly)
library(alpaca)
library(lmtest)
library(sandwich)
# library(mnlogit)

library(foreach)#parallel foreach
library(iterators)
library(parallel)
library(doParallel)

library(msm)
library(tikzDevice)

library(openxlsx)#read.xlsx

library(labelled)#change labels to columns

options(width=1000)#set max characters shown
options(max.print=100000)#set max rows shown console

# !diagnostics suppress=Dsvr,Dgdm

rm(list=ls())
cat("\014")
```



``` r
#READ DATA:----

#read TEV:
dt=read_sav("ZA5054_stacked_v1-0-0.sav", encoding = "latin1")

#read de wide:
load("d29_CSES-EV-LP.RData")#de wide (before making the long dataset)

#prepare TEV for variable manipulation:
dt=dt[!duplicated(dt$RRESPID),]#keep one observation by respondent

colnames(dt)[colnames(dt)=="COUNTRY"]="Ec"
dt$Ec=as.character(dt$Ec)
dt$Ec[dt$Ec=="1"]="AUT"#rename country code:
dt$Ec[dt$Ec=="4"]="HRV"
dt$Ec[dt$Ec=="7"]="EST"
dt$Ec[dt$Ec=="8"]="FIN"
dt$Ec[dt$Ec=="10"]="DEU"
dt$Ec[dt$Ec=="11"]="GRC"
dt$Ec[dt$Ec=="12"]="HUN"
dt$Ec[dt$Ec=="13"]="ISL"
dt$Ec[dt$Ec=="14"]="IRL"
dt$Ec[dt$Ec=="15"]="ITA"
dt$Ec[dt$Ec=="16"]="LTU"
dt$Ec[dt$Ec=="17"]="NLD"
dt$Ec[dt$Ec=="18"]="NOR"
dt$Ec[dt$Ec=="19"]="POL"
dt$Ec[dt$Ec=="20"]="PRT"
dt$Ec[dt$Ec=="21"]="ROU"
dt$Ec[dt$Ec=="22"]="SRB"
dt$Ec[dt$Ec=="23"]="SVN"
dt$Ec[dt$Ec=="24"]="ESP"
dt$Ec[dt$Ec=="25"]="SWE"
dt$Ec[dt$Ec=="26"]="CHE"
dt$Ec[dt$Ec=="27"]="GBR"
dt$Ec[dt$Ec=="28"]="TUR"

colnames(dt)[colnames(dt)=="YEAR"]="Ey"

dt$Es=paste0(dt$Ec,"_",dt$Ey)

colnames(dt)[colnames(dt)=="RAGE"]="Rage"#Respondent Age
dt$Rage=as.numeric(dt$Rage)
dt$Rage[dt$Rage>900]=NA

colnames(dt)[colnames(dt)=="RPART1"]="Vt"
dt$Vt=as.character(dt$Vt)
dt$Vt[dt$Vt!="1"&dt$Vt!="2"]=NA
dt$Vt[dt$Vt=="1"]="0"
dt$Vt[dt$Vt=="2"]="1"
dt$Vt=as.numeric(dt$Vt)

colnames(dt)[colnames(dt)=="RVOTE1"]="Vn"
dt$Vn=as.numeric(dt$Vn)
dt$Vn[dt$Vn>14]=NA#not coded Pl, Ll for these Vn (need to keep only Vn with STACKID)

#exclude East Germany in order to have West Germany as congruent electorate (and exclude Eastern Europe):
dt=dt[!(dt$Ec=="DEU"&dt$Ey>1990&dt$RREGION>10),]
#NB: in DEU_1990 even if the election included former East Germany, the survey did not

#Spain:
#set party like Convergence and Union as NA outside Cataluna:
# it is not in the top parties coded in 1979 1982 1993 2004
#set party like Basque Nationalist Party as NA outside Navarra and Pais Vasco:
# it is not in the top parties coded in 1979 1982 1993 2004
#set party like Republican Left of Catalonia as NA outside Cataluna and Comunidad Valenciana:
# it is not in the top parties coded in 1979 1982 1993 2004

#exclude Greek elections GRC_1989j for which there are only two parties coded, and keep in
# GRC_1989 only the November election:
dt=dt[!(dt$RSTUDYID==1119891),]

sort(unique(dew$Es))
```

```
##   [1] "ARG_2015"  "AUS_1993"  "AUS_1996"  "AUS_1998"  "AUS_2001"  "AUS_2004"  "AUS_2007"  "AUS_2013"  "AUS_2019"  "AUT_2013"  "AUT_2017"  "BGR_2014"  "CAN_1968"  "CAN_1974"  "CAN_1979"  "CAN_1988"  "CAN_1993"  "CAN_1997"  "CAN_2008"  "CAN_2011"  "CAN_2015"  "CZE_1996"  "CZE_2006"  "CZE_2010"  "CZE_2013"  "DEU_1961"  "DEU_1965"  "DEU_1976"  "DEU_1980"  "DEU_1983"  "DEU_1987"  "DEU_1990"  "DEU_1994"  "DEU_1998"  "DEU_2005"  "DEU_2009"  "DEU_2013"  "DEU_2017"  "DNK_1971"  "DNK_1973"  "DNK_1994"  "DNK_1998"  "DNK_2007"  "ESP_1996"  "ESP_2000"  "ESP_2008"  "FIN_2007"  "FIN_2011"  "FIN_2015"  "FRA_2007"  "GBR_1974f" "GBR_1974o" "GBR_1979"  "GBR_1997"  "GBR_2001"  "GBR_2015"  "GRC_2009"  "GRC_2012"  "GRC_2015j" "GRC_2015s" "HRV_2007"  "IRL_2007"  "IRL_2011"  "IRL_2016"  "ISL_1999"  "ISL_2007"  "ISL_2009"  "ISL_2013"  "ISL_2016"  "ISL_2017"  "ISR_1996"  "ISR_2006"  "ISR_2013"  "ITA_2018"  "LVA_2010"  "LVA_2011"  "LVA_2014"  "MEX_2000"  "MEX_2006"  "MEX_2009"  "MNE_2012"  "NLD_1986" 
##  [83] "NLD_1994"  "NLD_1998"  "NLD_2006"  "NLD_2010"  "NOR_1981"  "NOR_1985"  "NOR_1989"  "NOR_1993"  "NOR_1997"  "NOR_2005"  "NOR_2009"  "NOR_2013"  "NOR_2017"  "NZL_1996"  "NZL_2008"  "NZL_2011"  "NZL_2014"  "NZL_2017"  "PER_2001"  "PER_2011"  "PER_2016"  "POL_1997"  "POL_2005"  "POL_2007"  "POL_2011"  "PRT_2002"  "PRT_2009"  "PRT_2015"  "SRB_2012"  "SVK_2010"  "SVK_2016"  "SVN_1996"  "SVN_2008"  "SVN_2011"  "SWE_1982"  "SWE_1985"  "SWE_1988"  "SWE_1991"  "SWE_1994"  "SWE_1998"  "SWE_2006"  "SWE_2014"  "TWN_1996"  "ZAF_2009"  "ZAF_2014"
```

``` r
sort(unique(dt$Es))
```

```
##   [1] "AUT_2008" "CHE_1971" "CHE_1975" "CHE_1979" "CHE_1987" "CHE_1991" "CHE_1995" "CHE_1999" "CHE_2003" "CHE_2007" "CHE_2011" "DEU_1961" "DEU_1965" "DEU_1969" "DEU_1972" "DEU_1976" "DEU_1980" "DEU_1983" "DEU_1987" "DEU_1990" "DEU_1994" "DEU_1998" "DEU_2002" "DEU_2005" "DEU_2009" "DEU_2013" "ESP_1979" "ESP_1982" "ESP_1993" "ESP_2004" "EST_2007" "EST_2011" "FIN_2003" "FIN_2007" "FIN_2011" "GBR_2005" "GRC_1985" "GRC_1989" "GRC_1990" "GRC_1993" "GRC_1996" "GRC_2000" "GRC_2004" "GRC_2007" "GRC_2009" "GRC_2012" "HRV_1995" "HRV_2000" "HRV_2003" "HRV_2007" "HUN_1990" "HUN_1994" "HUN_1998" "HUN_2002" "HUN_2006" "IRL_2002" "IRL_2007" "IRL_2011" "ISL_1983" "ISL_1987" "ISL_1991" "ISL_1995" "ISL_1999" "ISL_2003" "ISL_2007" "ISL_2009" "ISL_2013" "ITA_1972" "ITA_1992" "ITA_1994" "ITA_1996" "ITA_2001" "ITA_2006" "ITA_2008" "ITA_2013" "LTU_1992" "LTU_1996" "LTU_2000" "LTU_2004" "LTU_2008" "NLD_1971" "NLD_1972" "NLD_1977" "NLD_1981" "NLD_1982" "NLD_1986" "NLD_1989" "NLD_1994" "NLD_1998" "NLD_2002"
##  [91] "NLD_2003" "NLD_2006" "NOR_1965" "NOR_1969" "NOR_1973" "NOR_1977" "NOR_1981" "NOR_1985" "NOR_1989" "NOR_1993" "NOR_1997" "NOR_2001" "NOR_2005" "POL_1997" "POL_2001" "POL_2005" "POL_2007" "POL_2011" "PRT_1985" "PRT_2002" "PRT_2005" "PRT_2006" "PRT_2009" "ROU_1996" "ROU_2000" "ROU_2004" "ROU_2008" "SRB_1990" "SRB_1992" "SRB_1993" "SRB_1997" "SRB_2001" "SRB_2002" "SRB_2003" "SRB_2004" "SVN_2000" "SVN_2004" "SVN_2008" "SWE_1956" "SWE_1960" "SWE_1964" "SWE_1968" "SWE_1970" "SWE_1973" "SWE_1976" "SWE_1979" "SWE_1982" "SWE_1985" "SWE_1988" "SWE_1991" "SWE_1994" "SWE_1998" "SWE_2002" "SWE_2006" "SWE_2010"
```

``` r
#Va (re-code vote according to party size):----
dt$Va=NA

dt$Va[dt$Es=="ESP_1979"&dt$Vn==1]=1
dt$Va[dt$Es=="ESP_1979"&dt$Vn==2]=2
dt$Va[dt$Es=="ESP_1979"&dt$Vn==3]=3
dt$Va[dt$Es=="ESP_1979"&dt$Vn==4]=4

dt$Va[dt$Es=="ESP_1982"&dt$Vn==3]=1
dt$Va[dt$Es=="ESP_1982"&dt$Vn==2]=2
dt$Va[dt$Es=="ESP_1982"&dt$Vn==4]=3
dt$Va[dt$Es=="ESP_1982"&dt$Vn==1]=4
dt$Va[dt$Es=="ESP_1982"&dt$Vn==5]=5

dt$Va[dt$Es=="ESP_1993"&dt$Vn==1]=1
dt$Va[dt$Es=="ESP_1993"&dt$Vn==3]=2
dt$Va[dt$Es=="ESP_1993"&dt$Vn==4]=3
dt$Va[dt$Es=="ESP_1993"&dt$Vn==2]=4

dt$Va[dt$Es=="ESP_2004"&dt$Vn==1]=1
dt$Va[dt$Es=="ESP_2004"&dt$Vn==2]=2
dt$Va[dt$Es=="ESP_2004"&dt$Vn==3]=3

dt$Va[dt$Es=="EST_2011"&dt$Vn==1]=1
dt$Va[dt$Es=="EST_2011"&dt$Vn==2]=2
dt$Va[dt$Es=="EST_2011"&dt$Vn==3]=3
dt$Va[dt$Es=="EST_2011"&dt$Vn==4]=4
dt$Va[dt$Es=="EST_2011"&dt$Vn==6]=5
dt$Va[dt$Es=="EST_2011"&dt$Vn==5]=6

dt$Va[dt$Es=="FIN_2003"&dt$Vn==1]=1
dt$Va[dt$Es=="FIN_2003"&dt$Vn==3]=2
dt$Va[dt$Es=="FIN_2003"&dt$Vn==2]=3
dt$Va[dt$Es=="FIN_2003"&dt$Vn==4]=4
dt$Va[dt$Es=="FIN_2003"&dt$Vn==5]=5
dt$Va[dt$Es=="FIN_2003"&dt$Vn==6]=6

dt$Va[dt$Es=="GBR_2005"&dt$Vn==1]=1
dt$Va[dt$Es=="GBR_2005"&dt$Vn==2]=2
dt$Va[dt$Es=="GBR_2005"&dt$Vn==3]=3

dt$Va[dt$Es=="GRC_1985"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_1985"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_1985"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_1985"&dt$Vn==4]=4

dt$Va[dt$Es=="GRC_1989"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_1989"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_1989"&dt$Vn==3]=3

dt$Va[dt$Es=="GRC_1990"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_1990"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_1990"&dt$Vn==3]=3

dt$Va[dt$Es=="GRC_1996"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_1996"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_1996"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_1996"&dt$Vn==4]=4
dt$Va[dt$Es=="GRC_1996"&dt$Vn==5]=5

dt$Va[dt$Es=="GRC_2000"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_2000"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_2000"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_2000"&dt$Vn==4]=4

dt$Va[dt$Es=="GRC_2004"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_2004"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_2004"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_2004"&dt$Vn==4]=4

dt$Va[dt$Es=="GRC_2007"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_2007"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_2007"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_2007"&dt$Vn==4]=4
dt$Va[dt$Es=="GRC_2007"&dt$Vn==5]=5

dt$Va[dt$Es=="HUN_1998"&dt$Vn==1]=1
dt$Va[dt$Es=="HUN_1998"&dt$Vn==5]=2
dt$Va[dt$Es=="HUN_1998"&dt$Vn==2]=3
dt$Va[dt$Es=="HUN_1998"&dt$Vn==6]=4
dt$Va[dt$Es=="HUN_1998"&dt$Vn==4]=5
dt$Va[dt$Es=="HUN_1998"&dt$Vn==3]=6

dt$Va[dt$Es=="HUN_2006"&dt$Vn==1]=1
dt$Va[dt$Es=="HUN_2006"&dt$Vn==2]=2
dt$Va[dt$Es=="HUN_2006"&dt$Vn==3]=3
dt$Va[dt$Es=="HUN_2006"&dt$Vn==4]=4

dt$Va[dt$Es=="IRL_2002"&dt$Vn==1]=1
dt$Va[dt$Es=="IRL_2002"&dt$Vn==2]=2
dt$Va[dt$Es=="IRL_2002"&dt$Vn==4]=3
dt$Va[dt$Es=="IRL_2002"&dt$Vn==5]=4
dt$Va[dt$Es=="IRL_2002"&dt$Vn==3]=5
dt$Va[dt$Es=="IRL_2002"&dt$Vn==6]=6

dt$Va[dt$Es=="ISL_1987"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_1987"&dt$Vn==2]=2
dt$Va[dt$Es=="ISL_1987"&dt$Vn==1]=3
dt$Va[dt$Es=="ISL_1987"&dt$Vn==4]=4
dt$Va[dt$Es=="ISL_1987"&dt$Vn==5]=5

dt$Va[dt$Es=="ISL_1991"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_1991"&dt$Vn==2]=2
dt$Va[dt$Es=="ISL_1991"&dt$Vn==1]=3
dt$Va[dt$Es=="ISL_1991"&dt$Vn==4]=4
dt$Va[dt$Es=="ISL_1991"&dt$Vn==5]=5

dt$Va[dt$Es=="ISL_1995"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_1995"&dt$Vn==2]=2
dt$Va[dt$Es=="ISL_1995"&dt$Vn==4]=3
dt$Va[dt$Es=="ISL_1995"&dt$Vn==1]=4
dt$Va[dt$Es=="ISL_1995"&dt$Vn==5]=5
dt$Va[dt$Es=="ISL_1995"&dt$Vn==6]=6

dt$Va[dt$Es=="ISL_2003"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_2003"&dt$Vn==1]=2
dt$Va[dt$Es=="ISL_2003"&dt$Vn==2]=3
dt$Va[dt$Es=="ISL_2003"&dt$Vn==4]=4
dt$Va[dt$Es=="ISL_2003"&dt$Vn==5]=5

dt$Va[dt$Es=="ITA_2006"&dt$Vn==3]=1#coalition==1
dt$Va[dt$Es=="ITA_2006"&dt$Vn==5]=2
dt$Va[dt$Es=="ITA_2006"&dt$Vn==6]=3
dt$Va[dt$Es=="ITA_2006"&dt$Vn==4]=4
dt$Va[dt$Es=="ITA_2006"&dt$Vn==1]=5
dt$Va[dt$Es=="ITA_2006"&dt$Vn==7]=6

dt$Va[dt$Es=="ITA_2008"&dt$Vn==4]=1#coalition==1
dt$Va[dt$Es=="ITA_2008"&dt$Vn==2]=2
dt$Va[dt$Es=="ITA_2008"&dt$Vn==5]=3
dt$Va[dt$Es=="ITA_2008"&dt$Vn==6]=4
dt$Va[dt$Es=="ITA_2008"&dt$Vn==3]=5
dt$Va[dt$Es=="ITA_2008"&dt$Vn==1]=6

dt$Va[dt$Es=="LTU_2000"&dt$Vn==2]=1
dt$Va[dt$Es=="LTU_2000"&dt$Vn==3]=2
dt$Va[dt$Es=="LTU_2000"&dt$Vn==4]=3
dt$Va[dt$Es=="LTU_2000"&dt$Vn==1]=4

dt$Va[dt$Es=="NLD_2002"&dt$Vn==2]=1
dt$Va[dt$Es=="NLD_2002"&dt$Vn==6]=2
dt$Va[dt$Es=="NLD_2002"&dt$Vn==3]=3
dt$Va[dt$Es=="NLD_2002"&dt$Vn==1]=4
dt$Va[dt$Es=="NLD_2002"&dt$Vn==5]=5
dt$Va[dt$Es=="NLD_2002"&dt$Vn==7]=6

dt$Va[dt$Es=="NOR_2001"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_2001"&dt$Vn==6]=2
dt$Va[dt$Es=="NOR_2001"&dt$Vn==7]=3
dt$Va[dt$Es=="NOR_2001"&dt$Vn==1]=4
dt$Va[dt$Es=="NOR_2001"&dt$Vn==4]=5
dt$Va[dt$Es=="NOR_2001"&dt$Vn==5]=6

dt$Va[dt$Es=="PRT_2005"&dt$Vn==5]=1
dt$Va[dt$Es=="PRT_2005"&dt$Vn==4]=2
dt$Va[dt$Es=="PRT_2005"&dt$Vn==3]=3
dt$Va[dt$Es=="PRT_2005"&dt$Vn==2]=4
dt$Va[dt$Es=="PRT_2005"&dt$Vn==1]=5

dt$Va[dt$Es=="SVN_2000"&dt$Vn==2]=1
dt$Va[dt$Es=="SVN_2000"&dt$Vn==5]=2
dt$Va[dt$Es=="SVN_2000"&dt$Vn==7]=3
dt$Va[dt$Es=="SVN_2000"&dt$Vn==3]=4
dt$Va[dt$Es=="SVN_2000"&dt$Vn==6]=5
dt$Va[dt$Es=="SVN_2000"&dt$Vn==1]=6

dt$Va[dt$Es=="SWE_1979"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1979"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1979"&dt$Vn==3]=3
dt$Va[dt$Es=="SWE_1979"&dt$Vn==4]=4
dt$Va[dt$Es=="SWE_1979"&dt$Vn==1]=5

dt$Va[dt$Es=="SWE_2002"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_2002"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_2002"&dt$Vn==4]=3
dt$Va[dt$Es=="SWE_2002"&dt$Vn==6]=4
dt$Va[dt$Es=="SWE_2002"&dt$Vn==1]=5
dt$Va[dt$Es=="SWE_2002"&dt$Vn==3]=6

dt$Va[dt$Es=="SWE_2010"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_2010"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_2010"&dt$Vn==7]=3
dt$Va[dt$Es=="SWE_2010"&dt$Vn==4]=4
dt$Va[dt$Es=="SWE_2010"&dt$Vn==3]=5
dt$Va[dt$Es=="SWE_2010"&dt$Vn==10]=6

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$Va[dt$Es=="DEU_1961"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1961"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1961"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1965"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1965"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1965"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1976"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1976"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1976"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1980"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1980"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1980"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1983"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1983"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1983"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1987"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1987"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1987"&dt$Vn==3]=3

dt$Va[dt$Es=="DEU_1990"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1990"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1990"&dt$Vn==3]=3
dt$Va[dt$Es=="DEU_1990"&dt$Vn==5]=4

dt$Va[dt$Es=="DEU_1994"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_1994"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_1994"&dt$Vn==4]=3
dt$Va[dt$Es=="DEU_1994"&dt$Vn==3]=4
dt$Va[dt$Es=="DEU_1994"&dt$Vn==5]=5

dt$Va[dt$Es=="DEU_1998"&dt$Vn==1]=1
dt$Va[dt$Es=="DEU_1998"&dt$Vn==2]=2
dt$Va[dt$Es=="DEU_1998"&dt$Vn==4]=3
dt$Va[dt$Es=="DEU_1998"&dt$Vn==3]=4
dt$Va[dt$Es=="DEU_1998"&dt$Vn==5]=5

dt$Va[dt$Es=="DEU_2009"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_2009"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_2009"&dt$Vn==3]=3
dt$Va[dt$Es=="DEU_2009"&dt$Vn==5]=4
dt$Va[dt$Es=="DEU_2009"&dt$Vn==4]=5

dt$Va[dt$Es=="DEU_2013"&dt$Vn==2]=1
dt$Va[dt$Es=="DEU_2013"&dt$Vn==1]=2
dt$Va[dt$Es=="DEU_2013"&dt$Vn==5]=3
dt$Va[dt$Es=="DEU_2013"&dt$Vn==4]=4
dt$Va[dt$Es=="DEU_2013"&dt$Vn==3]=5

dt$Va[dt$Es=="FIN_2007"&dt$Vn==1]=1
dt$Va[dt$Es=="FIN_2007"&dt$Vn==3]=2
dt$Va[dt$Es=="FIN_2007"&dt$Vn==2]=3
dt$Va[dt$Es=="FIN_2007"&dt$Vn==4]=4
dt$Va[dt$Es=="FIN_2007"&dt$Vn==5]=5
dt$Va[dt$Es=="FIN_2007"&dt$Vn==7]=6

dt$Va[dt$Es=="FIN_2011"&dt$Vn==3]=1
dt$Va[dt$Es=="FIN_2011"&dt$Vn==2]=2
dt$Va[dt$Es=="FIN_2011"&dt$Vn==8]=3
dt$Va[dt$Es=="FIN_2011"&dt$Vn==1]=4
dt$Va[dt$Es=="FIN_2011"&dt$Vn==4]=5
dt$Va[dt$Es=="FIN_2011"&dt$Vn==5]=6

dt$Va[dt$Es=="GRC_2009"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_2009"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_2009"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_2009"&dt$Vn==4]=4
dt$Va[dt$Es=="GRC_2009"&dt$Vn==5]=5
dt$Va[dt$Es=="GRC_2009"&dt$Vn==6]=6

dt$Va[dt$Es=="GRC_2012"&dt$Vn==1]=1
dt$Va[dt$Es=="GRC_2012"&dt$Vn==2]=2
dt$Va[dt$Es=="GRC_2012"&dt$Vn==3]=3
dt$Va[dt$Es=="GRC_2012"&dt$Vn==4]=4
dt$Va[dt$Es=="GRC_2012"&dt$Vn==5]=5
dt$Va[dt$Es=="GRC_2012"&dt$Vn==6]=6

dt$Va[dt$Es=="IRL_2007"&dt$Vn==1]=1
dt$Va[dt$Es=="IRL_2007"&dt$Vn==2]=2
dt$Va[dt$Es=="IRL_2007"&dt$Vn==4]=3
dt$Va[dt$Es=="IRL_2007"&dt$Vn==3]=4
dt$Va[dt$Es=="IRL_2007"&dt$Vn==6]=5
dt$Va[dt$Es=="IRL_2007"&dt$Vn==5]=6

dt$Va[dt$Es=="IRL_2011"&dt$Vn==2]=1
dt$Va[dt$Es=="IRL_2011"&dt$Vn==3]=2
dt$Va[dt$Es=="IRL_2011"&dt$Vn==1]=3
dt$Va[dt$Es=="IRL_2011"&dt$Vn==4]=4
dt$Va[dt$Es=="IRL_2011"&dt$Vn==5]=5#

dt$Va[dt$Es=="ISL_1999"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_1999"&dt$Vn==1]=2
dt$Va[dt$Es=="ISL_1999"&dt$Vn==2]=3
dt$Va[dt$Es=="ISL_1999"&dt$Vn==4]=4
dt$Va[dt$Es=="ISL_1999"&dt$Vn==5]=5

dt$Va[dt$Es=="ISL_2007"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_2007"&dt$Vn==1]=2
dt$Va[dt$Es=="ISL_2007"&dt$Vn==4]=3
dt$Va[dt$Es=="ISL_2007"&dt$Vn==2]=4
dt$Va[dt$Es=="ISL_2007"&dt$Vn==5]=5
dt$Va[dt$Es=="ISL_2007"&dt$Vn==6]=6#

dt$Va[dt$Es=="ISL_2009"&dt$Vn==1]=1
dt$Va[dt$Es=="ISL_2009"&dt$Vn==3]=2
dt$Va[dt$Es=="ISL_2009"&dt$Vn==4]=3
dt$Va[dt$Es=="ISL_2009"&dt$Vn==2]=4
dt$Va[dt$Es=="ISL_2009"&dt$Vn==5]=5#
dt$Va[dt$Es=="ISL_2009"&dt$Vn==6]=6#

dt$Va[dt$Es=="ISL_2013"&dt$Vn==3]=1
dt$Va[dt$Es=="ISL_2013"&dt$Vn==2]=2
dt$Va[dt$Es=="ISL_2013"&dt$Vn==1]=3
dt$Va[dt$Es=="ISL_2013"&dt$Vn==4]=4
dt$Va[dt$Es=="ISL_2013"&dt$Vn==5]=5
dt$Va[dt$Es=="ISL_2013"&dt$Vn==6]=6

dt$Va[dt$Es=="NLD_1994"&dt$Vn==1]=1
dt$Va[dt$Es=="NLD_1994"&dt$Vn==2]=2
dt$Va[dt$Es=="NLD_1994"&dt$Vn==3]=3
dt$Va[dt$Es=="NLD_1994"&dt$Vn==4]=4

dt$Va[dt$Es=="NLD_1998"&dt$Vn==1]=1#EV 4 parties, CSES 6 parties coded
dt$Va[dt$Es=="NLD_1998"&dt$Vn==3]=2
dt$Va[dt$Es=="NLD_1998"&dt$Vn==2]=3
dt$Va[dt$Es=="NLD_1998"&dt$Vn==4]=4
dt$Va[dt$Es=="NLD_1998"&dt$Vn==5]=5
dt$Va[dt$Es=="NLD_1998"&dt$Vn==7]=6#

dt$Va[dt$Es=="NOR_1981"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_1981"&dt$Vn==6]=2
dt$Va[dt$Es=="NOR_1981"&dt$Vn==4]=3
dt$Va[dt$Es=="NOR_1981"&dt$Vn==5]=4
dt$Va[dt$Es=="NOR_1981"&dt$Vn==1]=5
dt$Va[dt$Es=="NOR_1981"&dt$Vn==7]=6

dt$Va[dt$Es=="NOR_1985"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_1985"&dt$Vn==6]=2
dt$Va[dt$Es=="NOR_1985"&dt$Vn==4]=3
dt$Va[dt$Es=="NOR_1985"&dt$Vn==5]=4
dt$Va[dt$Es=="NOR_1985"&dt$Vn==1]=5
dt$Va[dt$Es=="NOR_1985"&dt$Vn==7]=6

dt$Va[dt$Es=="NOR_1989"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_1989"&dt$Vn==6]=2
dt$Va[dt$Es=="NOR_1989"&dt$Vn==7]=3
dt$Va[dt$Es=="NOR_1989"&dt$Vn==1]=4
dt$Va[dt$Es=="NOR_1989"&dt$Vn==4]=5
dt$Va[dt$Es=="NOR_1989"&dt$Vn==5]=6

dt$Va[dt$Es=="NOR_1993"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_1993"&dt$Vn==5]=2
dt$Va[dt$Es=="NOR_1993"&dt$Vn==6]=3
dt$Va[dt$Es=="NOR_1993"&dt$Vn==1]=4
dt$Va[dt$Es=="NOR_1993"&dt$Vn==4]=5
dt$Va[dt$Es=="NOR_1993"&dt$Vn==7]=6

dt$Va[dt$Es=="NOR_1997"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_1997"&dt$Vn==7]=2
dt$Va[dt$Es=="NOR_1997"&dt$Vn==4]=3
dt$Va[dt$Es=="NOR_1997"&dt$Vn==6]=4
dt$Va[dt$Es=="NOR_1997"&dt$Vn==5]=5
dt$Va[dt$Es=="NOR_1997"&dt$Vn==1]=6

dt$Va[dt$Es=="NOR_2005"&dt$Vn==2]=1
dt$Va[dt$Es=="NOR_2005"&dt$Vn==7]=2
dt$Va[dt$Es=="NOR_2005"&dt$Vn==6]=3
dt$Va[dt$Es=="NOR_2005"&dt$Vn==1]=4
dt$Va[dt$Es=="NOR_2005"&dt$Vn==4]=5
dt$Va[dt$Es=="NOR_2005"&dt$Vn==5]=6

dt$Va[dt$Es=="PRT_2002"&dt$Vn==4]=1
dt$Va[dt$Es=="PRT_2002"&dt$Vn==5]=2
dt$Va[dt$Es=="PRT_2002"&dt$Vn==2]=3
dt$Va[dt$Es=="PRT_2002"&dt$Vn==3]=4
dt$Va[dt$Es=="PRT_2002"&dt$Vn==1]=5
dt$Va[dt$Es=="PRT_2002"&dt$Vn==6]=6

dt$Va[dt$Es=="PRT_2009"&dt$Vn==5]=1#osym4-5  inverted!?
dt$Va[dt$Es=="PRT_2009"&dt$Vn==4]=2
dt$Va[dt$Es=="PRT_2009"&dt$Vn==2]=3
dt$Va[dt$Es=="PRT_2009"&dt$Vn==1]=4
dt$Va[dt$Es=="PRT_2009"&dt$Vn==3]=5

dt$Va[dt$Es=="SWE_1982"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1982"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1982"&dt$Vn==3]=3
dt$Va[dt$Es=="SWE_1982"&dt$Vn==4]=4
dt$Va[dt$Es=="SWE_1982"&dt$Vn==1]=5

dt$Va[dt$Es=="SWE_1985"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1985"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1985"&dt$Vn==4]=3
dt$Va[dt$Es=="SWE_1985"&dt$Vn==3]=4
dt$Va[dt$Es=="SWE_1985"&dt$Vn==1]=5
dt$Va[dt$Es=="SWE_1985"&dt$Vn==6]=6

dt$Va[dt$Es=="SWE_1988"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1988"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1988"&dt$Vn==4]=3
dt$Va[dt$Es=="SWE_1988"&dt$Vn==3]=4
dt$Va[dt$Es=="SWE_1988"&dt$Vn==1]=5

dt$Va[dt$Es=="SWE_1991"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1991"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1991"&dt$Vn==4]=3
dt$Va[dt$Es=="SWE_1991"&dt$Vn==3]=4
dt$Va[dt$Es=="SWE_1991"&dt$Vn==6]=5
dt$Va[dt$Es=="SWE_1991"&dt$Vn==9]=6

dt$Va[dt$Es=="SWE_1994"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1994"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1994"&dt$Vn==3]=3
dt$Va[dt$Es=="SWE_1994"&dt$Vn==4]=4
dt$Va[dt$Es=="SWE_1994"&dt$Vn==1]=5
dt$Va[dt$Es=="SWE_1994"&dt$Vn==7]=6

dt$Va[dt$Es=="SWE_1998"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_1998"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_1998"&dt$Vn==1]=3
dt$Va[dt$Es=="SWE_1998"&dt$Vn==6]=4
dt$Va[dt$Es=="SWE_1998"&dt$Vn==3]=5
dt$Va[dt$Es=="SWE_1998"&dt$Vn==4]=6

dt$Va[dt$Es=="SWE_2006"&dt$Vn==2]=1
dt$Va[dt$Es=="SWE_2006"&dt$Vn==5]=2
dt$Va[dt$Es=="SWE_2006"&dt$Vn==3]=3
dt$Va[dt$Es=="SWE_2006"&dt$Vn==4]=4
dt$Va[dt$Es=="SWE_2006"&dt$Vn==6]=5
dt$Va[dt$Es=="SWE_2006"&dt$Vn==1]=6


#party likability:----
dt$Pl.1=NA#create Pl:
dt$Pl.2=NA
dt$Pl.3=NA
dt$Pl.4=NA
dt$Pl.5=NA
dt$Pl.6=NA

dt$Pl.1[dt$Es=="ESP_1979"]=dt$RSYM1[dt$Es=="ESP_1979"]#assign Pl by party size order for parties with likability:
dt$Pl.2[dt$Es=="ESP_1979"]=dt$RSYM2[dt$Es=="ESP_1979"]
dt$Pl.3[dt$Es=="ESP_1979"]=dt$RSYM3[dt$Es=="ESP_1979"]
dt$Pl.4[dt$Es=="ESP_1979"]=dt$RSYM4[dt$Es=="ESP_1979"]

dt$Pl.1[dt$Es=="ESP_1982"]=dt$RSYM3[dt$Es=="ESP_1982"]
dt$Pl.2[dt$Es=="ESP_1982"]=dt$RSYM2[dt$Es=="ESP_1982"]
dt$Pl.3[dt$Es=="ESP_1982"]=dt$RSYM4[dt$Es=="ESP_1982"]
dt$Pl.4[dt$Es=="ESP_1982"]=dt$RSYM1[dt$Es=="ESP_1982"]
dt$Pl.5[dt$Es=="ESP_1982"]=dt$RSYM5[dt$Es=="ESP_1982"]

dt$Pl.1[dt$Es=="ESP_1993"]=dt$RSYM1[dt$Es=="ESP_1993"]
dt$Pl.2[dt$Es=="ESP_1993"]=dt$RSYM3[dt$Es=="ESP_1993"]
dt$Pl.3[dt$Es=="ESP_1993"]=dt$RSYM4[dt$Es=="ESP_1993"]
dt$Pl.4[dt$Es=="ESP_1993"]=dt$RSYM2[dt$Es=="ESP_1993"]

dt$Pl.1[dt$Es=="ESP_2004"]=dt$RSYM1[dt$Es=="ESP_2004"]
dt$Pl.2[dt$Es=="ESP_2004"]=dt$RSYM2[dt$Es=="ESP_2004"]
dt$Pl.3[dt$Es=="ESP_2004"]=dt$RSYM3[dt$Es=="ESP_2004"]

dt$Pl.1[dt$Es=="EST_2011"]=dt$RSYM1[dt$Es=="EST_2011"]
dt$Pl.2[dt$Es=="EST_2011"]=dt$RSYM2[dt$Es=="EST_2011"]
dt$Pl.3[dt$Es=="EST_2011"]=dt$RSYM3[dt$Es=="EST_2011"]
dt$Pl.4[dt$Es=="EST_2011"]=dt$RSYM4[dt$Es=="EST_2011"]
dt$Pl.5[dt$Es=="EST_2011"]=dt$RSYM6[dt$Es=="EST_2011"]
dt$Pl.6[dt$Es=="EST_2011"]=dt$RSYM5[dt$Es=="EST_2011"]

dt$Pl.1[dt$Es=="FIN_2003"]=dt$RSYM1[dt$Es=="FIN_2003"]
dt$Pl.2[dt$Es=="FIN_2003"]=dt$RSYM3[dt$Es=="FIN_2003"]
dt$Pl.3[dt$Es=="FIN_2003"]=dt$RSYM2[dt$Es=="FIN_2003"]
dt$Pl.4[dt$Es=="FIN_2003"]=dt$RSYM4[dt$Es=="FIN_2003"]
dt$Pl.5[dt$Es=="FIN_2003"]=dt$RSYM5[dt$Es=="FIN_2003"]
dt$Pl.6[dt$Es=="FIN_2003"]=dt$RSYM6[dt$Es=="FIN_2003"]

dt$Pl.1[dt$Es=="GBR_2005"]=dt$RSYM1[dt$Es=="GBR_2005"]
dt$Pl.2[dt$Es=="GBR_2005"]=dt$RSYM2[dt$Es=="GBR_2005"]
dt$Pl.3[dt$Es=="GBR_2005"]=dt$RSYM3[dt$Es=="GBR_2005"]

dt$Pl.1[dt$Es=="GRC_1985"]=dt$RSYM1[dt$Es=="GRC_1985"]
dt$Pl.2[dt$Es=="GRC_1985"]=dt$RSYM2[dt$Es=="GRC_1985"]
dt$Pl.3[dt$Es=="GRC_1985"]=dt$RSYM3[dt$Es=="GRC_1985"]
dt$Pl.4[dt$Es=="GRC_1985"]=dt$RSYM4[dt$Es=="GRC_1985"]

dt$Pl.1[dt$Es=="GRC_1989"]=dt$RSYM1[dt$Es=="GRC_1989"]
dt$Pl.2[dt$Es=="GRC_1989"]=dt$RSYM2[dt$Es=="GRC_1989"]
dt$Pl.3[dt$Es=="GRC_1989"]=dt$RSYM3[dt$Es=="GRC_1989"]

dt$Pl.1[dt$Es=="GRC_1990"]=dt$RSYM1[dt$Es=="GRC_1990"]
dt$Pl.2[dt$Es=="GRC_1990"]=dt$RSYM2[dt$Es=="GRC_1990"]
dt$Pl.3[dt$Es=="GRC_1990"]=dt$RSYM3[dt$Es=="GRC_1990"]

dt$Pl.1[dt$Es=="GRC_1996"]=dt$RSYM1[dt$Es=="GRC_1996"]
dt$Pl.2[dt$Es=="GRC_1996"]=dt$RSYM2[dt$Es=="GRC_1996"]
dt$Pl.3[dt$Es=="GRC_1996"]=dt$RSYM3[dt$Es=="GRC_1996"]
dt$Pl.4[dt$Es=="GRC_1996"]=dt$RSYM4[dt$Es=="GRC_1996"]
dt$Pl.5[dt$Es=="GRC_1996"]=dt$RSYM5[dt$Es=="GRC_1996"]

dt$Pl.1[dt$Es=="GRC_2000"]=dt$RSYM1[dt$Es=="GRC_2000"]
dt$Pl.2[dt$Es=="GRC_2000"]=dt$RSYM2[dt$Es=="GRC_2000"]
dt$Pl.3[dt$Es=="GRC_2000"]=dt$RSYM3[dt$Es=="GRC_2000"]
dt$Pl.4[dt$Es=="GRC_2000"]=dt$RSYM4[dt$Es=="GRC_2000"]

dt$Pl.1[dt$Es=="GRC_2004"]=dt$RSYM1[dt$Es=="GRC_2004"]
dt$Pl.2[dt$Es=="GRC_2004"]=dt$RSYM2[dt$Es=="GRC_2004"]
dt$Pl.3[dt$Es=="GRC_2004"]=dt$RSYM3[dt$Es=="GRC_2004"]
dt$Pl.4[dt$Es=="GRC_2004"]=dt$RSYM4[dt$Es=="GRC_2004"]

dt$Pl.1[dt$Es=="GRC_2007"]=dt$RSYM1[dt$Es=="GRC_2007"]
dt$Pl.2[dt$Es=="GRC_2007"]=dt$RSYM2[dt$Es=="GRC_2007"]
dt$Pl.3[dt$Es=="GRC_2007"]=dt$RSYM3[dt$Es=="GRC_2007"]
dt$Pl.4[dt$Es=="GRC_2007"]=dt$RSYM4[dt$Es=="GRC_2007"]
dt$Pl.5[dt$Es=="GRC_2007"]=dt$RSYM5[dt$Es=="GRC_2007"]

dt$Pl.1[dt$Es=="HUN_1998"]=dt$RSYM1[dt$Es=="HUN_1998"]
dt$Pl.2[dt$Es=="HUN_1998"]=dt$RSYM5[dt$Es=="HUN_1998"]
dt$Pl.3[dt$Es=="HUN_1998"]=dt$RSYM2[dt$Es=="HUN_1998"]
dt$Pl.4[dt$Es=="HUN_1998"]=dt$RSYM6[dt$Es=="HUN_1998"]
dt$Pl.5[dt$Es=="HUN_1998"]=dt$RSYM4[dt$Es=="HUN_1998"]
dt$Pl.6[dt$Es=="HUN_1998"]=dt$RSYM3[dt$Es=="HUN_1998"]

dt$Pl.1[dt$Es=="HUN_2006"]=dt$RSYM1[dt$Es=="HUN_2006"]
dt$Pl.2[dt$Es=="HUN_2006"]=dt$RSYM2[dt$Es=="HUN_2006"]
dt$Pl.3[dt$Es=="HUN_2006"]=dt$RSYM3[dt$Es=="HUN_2006"]
dt$Pl.4[dt$Es=="HUN_2006"]=dt$RSYM4[dt$Es=="HUN_2006"]

dt$Pl.1[dt$Es=="IRL_2002"]=dt$RSYM1[dt$Es=="IRL_2002"]
dt$Pl.2[dt$Es=="IRL_2002"]=dt$RSYM2[dt$Es=="IRL_2002"]
dt$Pl.3[dt$Es=="IRL_2002"]=dt$RSYM4[dt$Es=="IRL_2002"]
dt$Pl.4[dt$Es=="IRL_2002"]=dt$RSYM5[dt$Es=="IRL_2002"]
dt$Pl.5[dt$Es=="IRL_2002"]=dt$RSYM3[dt$Es=="IRL_2002"]
dt$Pl.6[dt$Es=="IRL_2002"]=dt$RSYM6[dt$Es=="IRL_2002"]

dt$Pl.1[dt$Es=="ISL_1987"]=dt$RSYM3[dt$Es=="ISL_1987"]
dt$Pl.2[dt$Es=="ISL_1987"]=dt$RSYM2[dt$Es=="ISL_1987"]
dt$Pl.3[dt$Es=="ISL_1987"]=dt$RSYM1[dt$Es=="ISL_1987"]
dt$Pl.4[dt$Es=="ISL_1987"]=dt$RSYM4[dt$Es=="ISL_1987"]
dt$Pl.5[dt$Es=="ISL_1987"]=dt$RSYM5[dt$Es=="ISL_1987"]

dt$Pl.1[dt$Es=="ISL_1991"]=dt$RSYM3[dt$Es=="ISL_1991"]
dt$Pl.2[dt$Es=="ISL_1991"]=dt$RSYM2[dt$Es=="ISL_1991"]
dt$Pl.3[dt$Es=="ISL_1991"]=dt$RSYM1[dt$Es=="ISL_1991"]
dt$Pl.4[dt$Es=="ISL_1991"]=dt$RSYM4[dt$Es=="ISL_1991"]
dt$Pl.5[dt$Es=="ISL_1991"]=dt$RSYM5[dt$Es=="ISL_1991"]

dt$Pl.1[dt$Es=="ISL_1995"]=dt$RSYM3[dt$Es=="ISL_1995"]
dt$Pl.2[dt$Es=="ISL_1995"]=dt$RSYM2[dt$Es=="ISL_1995"]
dt$Pl.3[dt$Es=="ISL_1995"]=dt$RSYM4[dt$Es=="ISL_1995"]
dt$Pl.4[dt$Es=="ISL_1995"]=dt$RSYM1[dt$Es=="ISL_1995"]
dt$Pl.5[dt$Es=="ISL_1995"]=dt$RSYM5[dt$Es=="ISL_1995"]
dt$Pl.6[dt$Es=="ISL_1995"]=dt$RSYM6[dt$Es=="ISL_1995"]

dt$Pl.1[dt$Es=="ISL_2003"]=dt$RSYM3[dt$Es=="ISL_2003"]
dt$Pl.2[dt$Es=="ISL_2003"]=dt$RSYM1[dt$Es=="ISL_2003"]
dt$Pl.3[dt$Es=="ISL_2003"]=dt$RSYM2[dt$Es=="ISL_2003"]
dt$Pl.4[dt$Es=="ISL_2003"]=dt$RSYM4[dt$Es=="ISL_2003"]
dt$Pl.5[dt$Es=="ISL_2003"]=dt$RSYM5[dt$Es=="ISL_2003"]

dt$Pl.1[dt$Es=="ITA_2006"]=dt$RSYM3[dt$Es=="ITA_2006"]#coalition==1
dt$Pl.2[dt$Es=="ITA_2006"]=dt$RSYM5[dt$Es=="ITA_2006"]
dt$Pl.3[dt$Es=="ITA_2006"]=dt$RSYM6[dt$Es=="ITA_2006"]
dt$Pl.4[dt$Es=="ITA_2006"]=dt$RSYM4[dt$Es=="ITA_2006"]
dt$Pl.5[dt$Es=="ITA_2006"]=dt$RSYM1[dt$Es=="ITA_2006"]
dt$Pl.6[dt$Es=="ITA_2006"]=dt$RSYM7[dt$Es=="ITA_2006"]

dt$Pl.1[dt$Es=="ITA_2008"]=dt$RSYM4[dt$Es=="ITA_2008"]#coalition==1
dt$Pl.2[dt$Es=="ITA_2008"]=dt$RSYM2[dt$Es=="ITA_2008"]
dt$Pl.3[dt$Es=="ITA_2008"]=dt$RSYM5[dt$Es=="ITA_2008"]
dt$Pl.4[dt$Es=="ITA_2008"]=dt$RSYM6[dt$Es=="ITA_2008"]
dt$Pl.5[dt$Es=="ITA_2008"]=dt$RSYM3[dt$Es=="ITA_2008"]
dt$Pl.6[dt$Es=="ITA_2008"]=dt$RSYM1[dt$Es=="ITA_2008"]

dt$Pl.1[dt$Es=="LTU_2000"]=dt$RSYM2[dt$Es=="LTU_2000"]
dt$Pl.2[dt$Es=="LTU_2000"]=dt$RSYM3[dt$Es=="LTU_2000"]
dt$Pl.3[dt$Es=="LTU_2000"]=dt$RSYM4[dt$Es=="LTU_2000"]
dt$Pl.4[dt$Es=="LTU_2000"]=dt$RSYM1[dt$Es=="LTU_2000"]

dt$Pl.1[dt$Es=="NLD_2002"]=dt$RSYM2[dt$Es=="NLD_2002"]
dt$Pl.2[dt$Es=="NLD_2002"]=dt$RSYM6[dt$Es=="NLD_2002"]
dt$Pl.3[dt$Es=="NLD_2002"]=dt$RSYM3[dt$Es=="NLD_2002"]
dt$Pl.4[dt$Es=="NLD_2002"]=dt$RSYM1[dt$Es=="NLD_2002"]
dt$Pl.5[dt$Es=="NLD_2002"]=dt$RSYM5[dt$Es=="NLD_2002"]
dt$Pl.6[dt$Es=="NLD_2002"]=dt$RSYM7[dt$Es=="NLD_2002"]

dt$Pl.1[dt$Es=="NOR_2001"]=dt$RSYM2[dt$Es=="NOR_2001"]
dt$Pl.2[dt$Es=="NOR_2001"]=dt$RSYM6[dt$Es=="NOR_2001"]
dt$Pl.3[dt$Es=="NOR_2001"]=dt$RSYM7[dt$Es=="NOR_2001"]
dt$Pl.4[dt$Es=="NOR_2001"]=dt$RSYM1[dt$Es=="NOR_2001"]
dt$Pl.5[dt$Es=="NOR_2001"]=dt$RSYM4[dt$Es=="NOR_2001"]
dt$Pl.6[dt$Es=="NOR_2001"]=dt$RSYM5[dt$Es=="NOR_2001"]

dt$Pl.1[dt$Es=="PRT_2005"]=dt$RSYM5[dt$Es=="PRT_2005"]
dt$Pl.2[dt$Es=="PRT_2005"]=dt$RSYM4[dt$Es=="PRT_2005"]
dt$Pl.3[dt$Es=="PRT_2005"]=dt$RSYM3[dt$Es=="PRT_2005"]
dt$Pl.4[dt$Es=="PRT_2005"]=dt$RSYM2[dt$Es=="PRT_2005"]
dt$Pl.5[dt$Es=="PRT_2005"]=dt$RSYM1[dt$Es=="PRT_2005"]

dt$Pl.1[dt$Es=="SVN_2000"]=dt$RSYM2[dt$Es=="SVN_2000"]
dt$Pl.2[dt$Es=="SVN_2000"]=dt$RSYM5[dt$Es=="SVN_2000"]
dt$Pl.3[dt$Es=="SVN_2000"]=dt$RSYM7[dt$Es=="SVN_2000"]
dt$Pl.4[dt$Es=="SVN_2000"]=dt$RSYM3[dt$Es=="SVN_2000"]
dt$Pl.5[dt$Es=="SVN_2000"]=dt$RSYM6[dt$Es=="SVN_2000"]
dt$Pl.6[dt$Es=="SVN_2000"]=dt$RSYM1[dt$Es=="SVN_2000"]

dt$Pl.1[dt$Es=="SWE_1979"]=dt$RSYM2[dt$Es=="SWE_1979"]
dt$Pl.2[dt$Es=="SWE_1979"]=dt$RSYM5[dt$Es=="SWE_1979"]
dt$Pl.3[dt$Es=="SWE_1979"]=dt$RSYM3[dt$Es=="SWE_1979"]
dt$Pl.4[dt$Es=="SWE_1979"]=dt$RSYM4[dt$Es=="SWE_1979"]
dt$Pl.5[dt$Es=="SWE_1979"]=dt$RSYM1[dt$Es=="SWE_1979"]

dt$Pl.1[dt$Es=="SWE_2002"]=dt$RSYM2[dt$Es=="SWE_2002"]
dt$Pl.2[dt$Es=="SWE_2002"]=dt$RSYM5[dt$Es=="SWE_2002"]
dt$Pl.3[dt$Es=="SWE_2002"]=dt$RSYM4[dt$Es=="SWE_2002"]
dt$Pl.4[dt$Es=="SWE_2002"]=dt$RSYM6[dt$Es=="SWE_2002"]
dt$Pl.5[dt$Es=="SWE_2002"]=dt$RSYM1[dt$Es=="SWE_2002"]
dt$Pl.6[dt$Es=="SWE_2002"]=dt$RSYM3[dt$Es=="SWE_2002"]

dt$Pl.1[dt$Es=="SWE_2010"]=dt$RSYM2[dt$Es=="SWE_2010"]
dt$Pl.2[dt$Es=="SWE_2010"]=dt$RSYM5[dt$Es=="SWE_2010"]
dt$Pl.3[dt$Es=="SWE_2010"]=dt$RSYM7[dt$Es=="SWE_2010"]
dt$Pl.4[dt$Es=="SWE_2010"]=dt$RSYM4[dt$Es=="SWE_2010"]
dt$Pl.5[dt$Es=="SWE_2010"]=dt$RSYM3[dt$Es=="SWE_2010"]
dt$Pl.6[dt$Es=="SWE_2010"]=dt$RSYM10[dt$Es=="SWE_2010"]

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$Pl.1[dt$Es=="DEU_1961"]=dt$RSYM2[dt$Es=="DEU_1961"]
dt$Pl.2[dt$Es=="DEU_1961"]=dt$RSYM1[dt$Es=="DEU_1961"]
dt$Pl.3[dt$Es=="DEU_1961"]=dt$RSYM3[dt$Es=="DEU_1961"]

dt$Pl.1[dt$Es=="DEU_1965"]=dt$RSYM2[dt$Es=="DEU_1965"]
dt$Pl.2[dt$Es=="DEU_1965"]=dt$RSYM1[dt$Es=="DEU_1965"]
dt$Pl.3[dt$Es=="DEU_1965"]=dt$RSYM3[dt$Es=="DEU_1965"]

dt$Pl.1[dt$Es=="DEU_1976"]=dt$RSYM2[dt$Es=="DEU_1976"]
dt$Pl.2[dt$Es=="DEU_1976"]=dt$RSYM1[dt$Es=="DEU_1976"]
dt$Pl.3[dt$Es=="DEU_1976"]=dt$RSYM3[dt$Es=="DEU_1976"]

dt$Pl.1[dt$Es=="DEU_1980"]=dt$RSYM2[dt$Es=="DEU_1980"]
dt$Pl.2[dt$Es=="DEU_1980"]=dt$RSYM1[dt$Es=="DEU_1980"]
dt$Pl.3[dt$Es=="DEU_1980"]=dt$RSYM3[dt$Es=="DEU_1980"]

dt$Pl.1[dt$Es=="DEU_1983"]=dt$RSYM2[dt$Es=="DEU_1983"]
dt$Pl.2[dt$Es=="DEU_1983"]=dt$RSYM1[dt$Es=="DEU_1983"]
dt$Pl.3[dt$Es=="DEU_1983"]=dt$RSYM3[dt$Es=="DEU_1983"]

dt$Pl.1[dt$Es=="DEU_1987"]=dt$RSYM2[dt$Es=="DEU_1987"]
dt$Pl.2[dt$Es=="DEU_1987"]=dt$RSYM1[dt$Es=="DEU_1987"]
dt$Pl.3[dt$Es=="DEU_1987"]=dt$RSYM3[dt$Es=="DEU_1987"]

dt$Pl.1[dt$Es=="DEU_1990"]=dt$RSYM2[dt$Es=="DEU_1990"]
dt$Pl.2[dt$Es=="DEU_1990"]=dt$RSYM1[dt$Es=="DEU_1990"]
dt$Pl.3[dt$Es=="DEU_1990"]=dt$RSYM3[dt$Es=="DEU_1990"]
dt$Pl.4[dt$Es=="DEU_1990"]=dt$RSYM5[dt$Es=="DEU_1990"]

dt$Pl.1[dt$Es=="DEU_1994"]=dt$RSYM2[dt$Es=="DEU_1994"]
dt$Pl.2[dt$Es=="DEU_1994"]=dt$RSYM1[dt$Es=="DEU_1994"]
dt$Pl.3[dt$Es=="DEU_1994"]=dt$RSYM4[dt$Es=="DEU_1994"]
dt$Pl.4[dt$Es=="DEU_1994"]=dt$RSYM3[dt$Es=="DEU_1994"]
dt$Pl.5[dt$Es=="DEU_1994"]=dt$RSYM5[dt$Es=="DEU_1994"]

dt$Pl.1[dt$Es=="DEU_1998"]=dt$RSYM1[dt$Es=="DEU_1998"]
dt$Pl.2[dt$Es=="DEU_1998"]=dt$RSYM2[dt$Es=="DEU_1998"]
dt$Pl.3[dt$Es=="DEU_1998"]=dt$RSYM4[dt$Es=="DEU_1998"]
dt$Pl.4[dt$Es=="DEU_1998"]=dt$RSYM3[dt$Es=="DEU_1998"]
dt$Pl.5[dt$Es=="DEU_1998"]=dt$RSYM5[dt$Es=="DEU_1998"]

dt$Pl.1[dt$Es=="DEU_2009"]=dt$RSYM2[dt$Es=="DEU_2009"]
dt$Pl.2[dt$Es=="DEU_2009"]=dt$RSYM1[dt$Es=="DEU_2009"]
dt$Pl.3[dt$Es=="DEU_2009"]=dt$RSYM3[dt$Es=="DEU_2009"]
dt$Pl.4[dt$Es=="DEU_2009"]=dt$RSYM5[dt$Es=="DEU_2009"]
dt$Pl.5[dt$Es=="DEU_2009"]=dt$RSYM4[dt$Es=="DEU_2009"]

dt$Pl.1[dt$Es=="DEU_2013"]=dt$RSYM2[dt$Es=="DEU_2013"]
dt$Pl.2[dt$Es=="DEU_2013"]=dt$RSYM1[dt$Es=="DEU_2013"]
dt$Pl.3[dt$Es=="DEU_2013"]=dt$RSYM5[dt$Es=="DEU_2013"]
dt$Pl.4[dt$Es=="DEU_2013"]=dt$RSYM4[dt$Es=="DEU_2013"]
dt$Pl.5[dt$Es=="DEU_2013"]=dt$RSYM3[dt$Es=="DEU_2013"]

dt$Pl.1[dt$Es=="FIN_2007"]=dt$RSYM1[dt$Es=="FIN_2007"]
dt$Pl.2[dt$Es=="FIN_2007"]=dt$RSYM3[dt$Es=="FIN_2007"]
dt$Pl.3[dt$Es=="FIN_2007"]=dt$RSYM2[dt$Es=="FIN_2007"]
dt$Pl.4[dt$Es=="FIN_2007"]=dt$RSYM4[dt$Es=="FIN_2007"]
dt$Pl.5[dt$Es=="FIN_2007"]=dt$RSYM5[dt$Es=="FIN_2007"]
dt$Pl.6[dt$Es=="FIN_2007"]=dt$RSYM7[dt$Es=="FIN_2007"]

dt$Pl.1[dt$Es=="FIN_2011"]=dt$RSYM3[dt$Es=="FIN_2011"]
dt$Pl.2[dt$Es=="FIN_2011"]=dt$RSYM2[dt$Es=="FIN_2011"]
dt$Pl.3[dt$Es=="FIN_2011"]=dt$RSYM8[dt$Es=="FIN_2011"]
dt$Pl.4[dt$Es=="FIN_2011"]=dt$RSYM1[dt$Es=="FIN_2011"]
dt$Pl.5[dt$Es=="FIN_2011"]=dt$RSYM4[dt$Es=="FIN_2011"]
dt$Pl.6[dt$Es=="FIN_2011"]=dt$RSYM5[dt$Es=="FIN_2011"]

dt$Pl.1[dt$Es=="GRC_2009"]=dt$RSYM1[dt$Es=="GRC_2009"]
dt$Pl.2[dt$Es=="GRC_2009"]=dt$RSYM2[dt$Es=="GRC_2009"]
dt$Pl.3[dt$Es=="GRC_2009"]=dt$RSYM3[dt$Es=="GRC_2009"]
dt$Pl.4[dt$Es=="GRC_2009"]=dt$RSYM4[dt$Es=="GRC_2009"]
dt$Pl.5[dt$Es=="GRC_2009"]=dt$RSYM5[dt$Es=="GRC_2009"]
dt$Pl.6[dt$Es=="GRC_2009"]=dt$RSYM6[dt$Es=="GRC_2009"]

dt$Pl.1[dt$Es=="GRC_2012"]=dt$RSYM1[dt$Es=="GRC_2012"]
dt$Pl.2[dt$Es=="GRC_2012"]=dt$RSYM2[dt$Es=="GRC_2012"]
dt$Pl.3[dt$Es=="GRC_2012"]=dt$RSYM3[dt$Es=="GRC_2012"]
dt$Pl.4[dt$Es=="GRC_2012"]=dt$RSYM4[dt$Es=="GRC_2012"]
dt$Pl.5[dt$Es=="GRC_2012"]=dt$RSYM5[dt$Es=="GRC_2012"]
dt$Pl.6[dt$Es=="GRC_2012"]=dt$RSYM6[dt$Es=="GRC_2012"]

dt$Pl.1[dt$Es=="IRL_2007"]=dt$RSYM1[dt$Es=="IRL_2007"]
dt$Pl.2[dt$Es=="IRL_2007"]=dt$RSYM2[dt$Es=="IRL_2007"]
dt$Pl.3[dt$Es=="IRL_2007"]=dt$RSYM4[dt$Es=="IRL_2007"]
dt$Pl.4[dt$Es=="IRL_2007"]=dt$RSYM3[dt$Es=="IRL_2007"]
dt$Pl.5[dt$Es=="IRL_2007"]=dt$RSYM6[dt$Es=="IRL_2007"]
dt$Pl.6[dt$Es=="IRL_2007"]=dt$RSYM5[dt$Es=="IRL_2007"]

dt$Pl.1[dt$Es=="IRL_2011"]=dt$RSYM2[dt$Es=="IRL_2011"]
dt$Pl.2[dt$Es=="IRL_2011"]=dt$RSYM3[dt$Es=="IRL_2011"]
dt$Pl.3[dt$Es=="IRL_2011"]=dt$RSYM1[dt$Es=="IRL_2011"]
dt$Pl.4[dt$Es=="IRL_2011"]=dt$RSYM4[dt$Es=="IRL_2011"]
dt$Pl.5[dt$Es=="IRL_2011"]=dt$RSYM5[dt$Es=="IRL_2011"]#

dt$Pl.1[dt$Es=="ISL_1999"]=dt$RSYM3[dt$Es=="ISL_1999"]
dt$Pl.2[dt$Es=="ISL_1999"]=dt$RSYM1[dt$Es=="ISL_1999"]
dt$Pl.3[dt$Es=="ISL_1999"]=dt$RSYM2[dt$Es=="ISL_1999"]
dt$Pl.4[dt$Es=="ISL_1999"]=dt$RSYM4[dt$Es=="ISL_1999"]
dt$Pl.5[dt$Es=="ISL_1999"]=dt$RSYM5[dt$Es=="ISL_1999"]

dt$Pl.1[dt$Es=="ISL_2007"]=dt$RSYM3[dt$Es=="ISL_2007"]
dt$Pl.2[dt$Es=="ISL_2007"]=dt$RSYM1[dt$Es=="ISL_2007"]
dt$Pl.3[dt$Es=="ISL_2007"]=dt$RSYM4[dt$Es=="ISL_2007"]
dt$Pl.4[dt$Es=="ISL_2007"]=dt$RSYM2[dt$Es=="ISL_2007"]
dt$Pl.5[dt$Es=="ISL_2007"]=dt$RSYM5[dt$Es=="ISL_2007"]
dt$Pl.6[dt$Es=="ISL_2007"]=dt$RSYM6[dt$Es=="ISL_2007"]#

dt$Pl.1[dt$Es=="ISL_2009"]=dt$RSYM1[dt$Es=="ISL_2009"]
dt$Pl.2[dt$Es=="ISL_2009"]=dt$RSYM3[dt$Es=="ISL_2009"]
dt$Pl.3[dt$Es=="ISL_2009"]=dt$RSYM4[dt$Es=="ISL_2009"]
dt$Pl.4[dt$Es=="ISL_2009"]=dt$RSYM2[dt$Es=="ISL_2009"]
dt$Pl.5[dt$Es=="ISL_2009"]=dt$RSYM5[dt$Es=="ISL_2009"]#
dt$Pl.6[dt$Es=="ISL_2009"]=dt$RSYM6[dt$Es=="ISL_2009"]#

dt$Pl.1[dt$Es=="ISL_2013"]=dt$RSYM3[dt$Es=="ISL_2013"]
dt$Pl.2[dt$Es=="ISL_2013"]=dt$RSYM2[dt$Es=="ISL_2013"]
dt$Pl.3[dt$Es=="ISL_2013"]=dt$RSYM1[dt$Es=="ISL_2013"]
dt$Pl.4[dt$Es=="ISL_2013"]=dt$RSYM4[dt$Es=="ISL_2013"]
dt$Pl.5[dt$Es=="ISL_2013"]=dt$RSYM5[dt$Es=="ISL_2013"]
dt$Pl.6[dt$Es=="ISL_2013"]=dt$RSYM6[dt$Es=="ISL_2013"]

dt$Pl.1[dt$Es=="NLD_1994"]=dt$RSYM1[dt$Es=="NLD_1994"]
dt$Pl.2[dt$Es=="NLD_1994"]=dt$RSYM2[dt$Es=="NLD_1994"]
dt$Pl.3[dt$Es=="NLD_1994"]=dt$RSYM3[dt$Es=="NLD_1994"]
dt$Pl.4[dt$Es=="NLD_1994"]=dt$RSYM4[dt$Es=="NLD_1994"]

dt$Pl.1[dt$Es=="NLD_1998"]=dt$RSYM1[dt$Es=="NLD_1998"]#EV 4 parties, CSES 6 parties coded
dt$Pl.2[dt$Es=="NLD_1998"]=dt$RSYM3[dt$Es=="NLD_1998"]
dt$Pl.3[dt$Es=="NLD_1998"]=dt$RSYM2[dt$Es=="NLD_1998"]
dt$Pl.4[dt$Es=="NLD_1998"]=dt$RSYM4[dt$Es=="NLD_1998"]
dt$Pl.5[dt$Es=="NLD_1998"]=dt$RSYM5[dt$Es=="NLD_1998"]
dt$Pl.6[dt$Es=="NLD_1998"]=dt$RSYM7[dt$Es=="NLD_1998"]#

dt$Pl.1[dt$Es=="NOR_1981"]=dt$RSYM2[dt$Es=="NOR_1981"]
dt$Pl.2[dt$Es=="NOR_1981"]=dt$RSYM6[dt$Es=="NOR_1981"]
dt$Pl.3[dt$Es=="NOR_1981"]=dt$RSYM4[dt$Es=="NOR_1981"]
dt$Pl.4[dt$Es=="NOR_1981"]=dt$RSYM5[dt$Es=="NOR_1981"]
dt$Pl.5[dt$Es=="NOR_1981"]=dt$RSYM1[dt$Es=="NOR_1981"]
dt$Pl.6[dt$Es=="NOR_1981"]=dt$RSYM7[dt$Es=="NOR_1981"]

dt$Pl.1[dt$Es=="NOR_1985"]=dt$RSYM2[dt$Es=="NOR_1985"]
dt$Pl.2[dt$Es=="NOR_1985"]=dt$RSYM6[dt$Es=="NOR_1985"]
dt$Pl.3[dt$Es=="NOR_1985"]=dt$RSYM4[dt$Es=="NOR_1985"]
dt$Pl.4[dt$Es=="NOR_1985"]=dt$RSYM5[dt$Es=="NOR_1985"]
dt$Pl.5[dt$Es=="NOR_1985"]=dt$RSYM1[dt$Es=="NOR_1985"]
dt$Pl.6[dt$Es=="NOR_1985"]=dt$RSYM7[dt$Es=="NOR_1985"]

dt$Pl.1[dt$Es=="NOR_1989"]=dt$RSYM2[dt$Es=="NOR_1989"]
dt$Pl.2[dt$Es=="NOR_1989"]=dt$RSYM6[dt$Es=="NOR_1989"]
dt$Pl.3[dt$Es=="NOR_1989"]=dt$RSYM7[dt$Es=="NOR_1989"]
dt$Pl.4[dt$Es=="NOR_1989"]=dt$RSYM1[dt$Es=="NOR_1989"]
dt$Pl.5[dt$Es=="NOR_1989"]=dt$RSYM4[dt$Es=="NOR_1989"]
dt$Pl.6[dt$Es=="NOR_1989"]=dt$RSYM5[dt$Es=="NOR_1989"]

dt$Pl.1[dt$Es=="NOR_1993"]=dt$RSYM2[dt$Es=="NOR_1993"]
dt$Pl.2[dt$Es=="NOR_1993"]=dt$RSYM5[dt$Es=="NOR_1993"]
dt$Pl.3[dt$Es=="NOR_1993"]=dt$RSYM6[dt$Es=="NOR_1993"]
dt$Pl.4[dt$Es=="NOR_1993"]=dt$RSYM1[dt$Es=="NOR_1993"]
dt$Pl.5[dt$Es=="NOR_1993"]=dt$RSYM4[dt$Es=="NOR_1993"]
dt$Pl.6[dt$Es=="NOR_1993"]=dt$RSYM7[dt$Es=="NOR_1993"]

dt$Pl.1[dt$Es=="NOR_1997"]=dt$RSYM2[dt$Es=="NOR_1997"]
dt$Pl.2[dt$Es=="NOR_1997"]=dt$RSYM7[dt$Es=="NOR_1997"]
dt$Pl.3[dt$Es=="NOR_1997"]=dt$RSYM4[dt$Es=="NOR_1997"]
dt$Pl.4[dt$Es=="NOR_1997"]=dt$RSYM6[dt$Es=="NOR_1997"]
dt$Pl.5[dt$Es=="NOR_1997"]=dt$RSYM5[dt$Es=="NOR_1997"]
dt$Pl.6[dt$Es=="NOR_1997"]=dt$RSYM1[dt$Es=="NOR_1997"]

dt$Pl.1[dt$Es=="NOR_2005"]=dt$RSYM2[dt$Es=="NOR_2005"]
dt$Pl.2[dt$Es=="NOR_2005"]=dt$RSYM7[dt$Es=="NOR_2005"]
dt$Pl.3[dt$Es=="NOR_2005"]=dt$RSYM6[dt$Es=="NOR_2005"]
dt$Pl.4[dt$Es=="NOR_2005"]=dt$RSYM1[dt$Es=="NOR_2005"]
dt$Pl.5[dt$Es=="NOR_2005"]=dt$RSYM4[dt$Es=="NOR_2005"]
dt$Pl.6[dt$Es=="NOR_2005"]=dt$RSYM5[dt$Es=="NOR_2005"]

dt$Pl.1[dt$Es=="PRT_2002"]=dt$RSYM4[dt$Es=="PRT_2002"]
dt$Pl.2[dt$Es=="PRT_2002"]=dt$RSYM5[dt$Es=="PRT_2002"]
dt$Pl.3[dt$Es=="PRT_2002"]=dt$RSYM2[dt$Es=="PRT_2002"]
dt$Pl.4[dt$Es=="PRT_2002"]=dt$RSYM3[dt$Es=="PRT_2002"]
dt$Pl.5[dt$Es=="PRT_2002"]=dt$RSYM1[dt$Es=="PRT_2002"]
dt$Pl.6[dt$Es=="PRT_2002"]=dt$RSYM6[dt$Es=="PRT_2002"]

dt$Pl.1[dt$Es=="PRT_2009"]=dt$RSYM5[dt$Es=="PRT_2009"]#osym4-5  inverted!?
dt$Pl.2[dt$Es=="PRT_2009"]=dt$RSYM4[dt$Es=="PRT_2009"]
dt$Pl.3[dt$Es=="PRT_2009"]=dt$RSYM2[dt$Es=="PRT_2009"]
dt$Pl.4[dt$Es=="PRT_2009"]=dt$RSYM1[dt$Es=="PRT_2009"]
dt$Pl.5[dt$Es=="PRT_2009"]=dt$RSYM3[dt$Es=="PRT_2009"]

dt$Pl.1[dt$Es=="SWE_1982"]=dt$RSYM2[dt$Es=="SWE_1982"]
dt$Pl.2[dt$Es=="SWE_1982"]=dt$RSYM5[dt$Es=="SWE_1982"]
dt$Pl.3[dt$Es=="SWE_1982"]=dt$RSYM3[dt$Es=="SWE_1982"]
dt$Pl.4[dt$Es=="SWE_1982"]=dt$RSYM4[dt$Es=="SWE_1982"]
dt$Pl.5[dt$Es=="SWE_1982"]=dt$RSYM1[dt$Es=="SWE_1982"]

dt$Pl.1[dt$Es=="SWE_1985"]=dt$RSYM2[dt$Es=="SWE_1985"]
dt$Pl.2[dt$Es=="SWE_1985"]=dt$RSYM5[dt$Es=="SWE_1985"]
dt$Pl.3[dt$Es=="SWE_1985"]=dt$RSYM4[dt$Es=="SWE_1985"]
dt$Pl.4[dt$Es=="SWE_1985"]=dt$RSYM3[dt$Es=="SWE_1985"]
dt$Pl.5[dt$Es=="SWE_1985"]=dt$RSYM1[dt$Es=="SWE_1985"]
dt$Pl.6[dt$Es=="SWE_1985"]=dt$RSYM6[dt$Es=="SWE_1985"]

dt$Pl.1[dt$Es=="SWE_1988"]=dt$RSYM2[dt$Es=="SWE_1988"]
dt$Pl.2[dt$Es=="SWE_1988"]=dt$RSYM5[dt$Es=="SWE_1988"]
dt$Pl.3[dt$Es=="SWE_1988"]=dt$RSYM4[dt$Es=="SWE_1988"]
dt$Pl.4[dt$Es=="SWE_1988"]=dt$RSYM3[dt$Es=="SWE_1988"]
dt$Pl.5[dt$Es=="SWE_1988"]=dt$RSYM1[dt$Es=="SWE_1988"]

dt$Pl.1[dt$Es=="SWE_1991"]=dt$RSYM2[dt$Es=="SWE_1991"]
dt$Pl.2[dt$Es=="SWE_1991"]=dt$RSYM5[dt$Es=="SWE_1991"]
dt$Pl.3[dt$Es=="SWE_1991"]=dt$RSYM4[dt$Es=="SWE_1991"]
dt$Pl.4[dt$Es=="SWE_1991"]=dt$RSYM3[dt$Es=="SWE_1991"]
dt$Pl.5[dt$Es=="SWE_1991"]=dt$RSYM6[dt$Es=="SWE_1991"]
dt$Pl.6[dt$Es=="SWE_1991"]=dt$RSYM9[dt$Es=="SWE_1991"]

dt$Pl.1[dt$Es=="SWE_1994"]=dt$RSYM2[dt$Es=="SWE_1994"]
dt$Pl.2[dt$Es=="SWE_1994"]=dt$RSYM5[dt$Es=="SWE_1994"]
dt$Pl.3[dt$Es=="SWE_1994"]=dt$RSYM3[dt$Es=="SWE_1994"]
dt$Pl.4[dt$Es=="SWE_1994"]=dt$RSYM4[dt$Es=="SWE_1994"]
dt$Pl.5[dt$Es=="SWE_1994"]=dt$RSYM1[dt$Es=="SWE_1994"]
dt$Pl.6[dt$Es=="SWE_1994"]=dt$RSYM7[dt$Es=="SWE_1994"]

dt$Pl.1[dt$Es=="SWE_1998"]=dt$RSYM2[dt$Es=="SWE_1998"]
dt$Pl.2[dt$Es=="SWE_1998"]=dt$RSYM5[dt$Es=="SWE_1998"]
dt$Pl.3[dt$Es=="SWE_1998"]=dt$RSYM1[dt$Es=="SWE_1998"]
dt$Pl.4[dt$Es=="SWE_1998"]=dt$RSYM6[dt$Es=="SWE_1998"]
dt$Pl.5[dt$Es=="SWE_1998"]=dt$RSYM3[dt$Es=="SWE_1998"]
dt$Pl.6[dt$Es=="SWE_1998"]=dt$RSYM4[dt$Es=="SWE_1998"]

dt$Pl.1[dt$Es=="SWE_2006"]=dt$RSYM2[dt$Es=="SWE_2006"]
dt$Pl.2[dt$Es=="SWE_2006"]=dt$RSYM5[dt$Es=="SWE_2006"]
dt$Pl.3[dt$Es=="SWE_2006"]=dt$RSYM3[dt$Es=="SWE_2006"]
dt$Pl.4[dt$Es=="SWE_2006"]=dt$RSYM4[dt$Es=="SWE_2006"]
dt$Pl.5[dt$Es=="SWE_2006"]=dt$RSYM6[dt$Es=="SWE_2006"]
dt$Pl.6[dt$Es=="SWE_2006"]=dt$RSYM1[dt$Es=="SWE_2006"]

dt$Pl.1=as.numeric(dt$Pl.1)#recode as numeric:
dt$Pl.2=as.numeric(dt$Pl.2)
dt$Pl.3=as.numeric(dt$Pl.3)
dt$Pl.4=as.numeric(dt$Pl.4)
dt$Pl.5=as.numeric(dt$Pl.5)
dt$Pl.6=as.numeric(dt$Pl.6)

dt$Pl.1[dt$Pl.1>1]=NA#exclude NAs coded 900s:
dt$Pl.2[dt$Pl.2>1]=NA
dt$Pl.3[dt$Pl.3>1]=NA
dt$Pl.4[dt$Pl.4>1]=NA
dt$Pl.5[dt$Pl.5>1]=NA
dt$Pl.6[dt$Pl.6>1]=NA

dt$Pl.1=dt$Pl.1*10#recode to 0-10 scale:
dt$Pl.2=dt$Pl.2*10
dt$Pl.3=dt$Pl.3*10
dt$Pl.4=dt$Pl.4*10
dt$Pl.5=dt$Pl.5*10
dt$Pl.6=dt$Pl.6*10

#leader likability:----
dt$Ll.1=NA#create Ll:
dt$Ll.2=NA
dt$Ll.3=NA
dt$Ll.4=NA
dt$Ll.5=NA
dt$Ll.6=NA

dt$Ll.1[dt$Es=="ESP_1979"]=dt$RSYML1[dt$Es=="ESP_1979"]#assign Ll by party size order for parties with likability:
dt$Ll.2[dt$Es=="ESP_1979"]=dt$RSYML2[dt$Es=="ESP_1979"]
dt$Ll.3[dt$Es=="ESP_1979"]=dt$RSYML3[dt$Es=="ESP_1979"]
dt$Ll.4[dt$Es=="ESP_1979"]=dt$RSYML4[dt$Es=="ESP_1979"]

dt$Ll.1[dt$Es=="ESP_1982"]=dt$RSYML3[dt$Es=="ESP_1982"]
dt$Ll.2[dt$Es=="ESP_1982"]=dt$RSYML2[dt$Es=="ESP_1982"]
dt$Ll.3[dt$Es=="ESP_1982"]=dt$RSYML4[dt$Es=="ESP_1982"]
dt$Ll.4[dt$Es=="ESP_1982"]=dt$RSYML1[dt$Es=="ESP_1982"]
dt$Ll.5[dt$Es=="ESP_1982"]=dt$RSYML5[dt$Es=="ESP_1982"]

dt$Ll.1[dt$Es=="ESP_1993"]=dt$RSYML1[dt$Es=="ESP_1993"]
dt$Ll.2[dt$Es=="ESP_1993"]=dt$RSYML3[dt$Es=="ESP_1993"]
dt$Ll.3[dt$Es=="ESP_1993"]=dt$RSYML4[dt$Es=="ESP_1993"]
dt$Ll.4[dt$Es=="ESP_1993"]=dt$RSYML2[dt$Es=="ESP_1993"]

dt$Ll.1[dt$Es=="ESP_2004"]=dt$RSYML1[dt$Es=="ESP_2004"]
dt$Ll.2[dt$Es=="ESP_2004"]=dt$RSYML2[dt$Es=="ESP_2004"]
dt$Ll.3[dt$Es=="ESP_2004"]=dt$RSYML3[dt$Es=="ESP_2004"]

dt$Ll.1[dt$Es=="EST_2011"]=dt$RSYML1[dt$Es=="EST_2011"]
dt$Ll.2[dt$Es=="EST_2011"]=dt$RSYML2[dt$Es=="EST_2011"]
dt$Ll.3[dt$Es=="EST_2011"]=dt$RSYML3[dt$Es=="EST_2011"]
dt$Ll.4[dt$Es=="EST_2011"]=dt$RSYML4[dt$Es=="EST_2011"]
dt$Ll.5[dt$Es=="EST_2011"]=dt$RSYML6[dt$Es=="EST_2011"]
dt$Ll.6[dt$Es=="EST_2011"]=dt$RSYML5[dt$Es=="EST_2011"]

dt$Ll.1[dt$Es=="FIN_2003"]=dt$RSYML1[dt$Es=="FIN_2003"]
dt$Ll.2[dt$Es=="FIN_2003"]=dt$RSYML3[dt$Es=="FIN_2003"]
dt$Ll.3[dt$Es=="FIN_2003"]=dt$RSYML2[dt$Es=="FIN_2003"]
dt$Ll.4[dt$Es=="FIN_2003"]=dt$RSYML4[dt$Es=="FIN_2003"]
dt$Ll.5[dt$Es=="FIN_2003"]=dt$RSYML5[dt$Es=="FIN_2003"]
dt$Ll.6[dt$Es=="FIN_2003"]=dt$RSYML6[dt$Es=="FIN_2003"]

dt$Ll.1[dt$Es=="GBR_2005"]=dt$RSYML1[dt$Es=="GBR_2005"]
dt$Ll.2[dt$Es=="GBR_2005"]=dt$RSYML2[dt$Es=="GBR_2005"]
dt$Ll.3[dt$Es=="GBR_2005"]=dt$RSYML3[dt$Es=="GBR_2005"]

dt$Ll.1[dt$Es=="GRC_1985"]=dt$RSYML1[dt$Es=="GRC_1985"]
dt$Ll.2[dt$Es=="GRC_1985"]=dt$RSYML2[dt$Es=="GRC_1985"]
dt$Ll.3[dt$Es=="GRC_1985"]=dt$RSYML3[dt$Es=="GRC_1985"]
dt$Ll.4[dt$Es=="GRC_1985"]=dt$RSYML4[dt$Es=="GRC_1985"]

dt$Ll.1[dt$Es=="GRC_1989"]=dt$RSYML1[dt$Es=="GRC_1989"]
dt$Ll.2[dt$Es=="GRC_1989"]=dt$RSYML2[dt$Es=="GRC_1989"]
dt$Ll.3[dt$Es=="GRC_1989"]=dt$RSYML3[dt$Es=="GRC_1989"]

dt$Ll.1[dt$Es=="GRC_1990"]=dt$RSYML1[dt$Es=="GRC_1990"]
dt$Ll.2[dt$Es=="GRC_1990"]=dt$RSYML2[dt$Es=="GRC_1990"]
dt$Ll.3[dt$Es=="GRC_1990"]=dt$RSYML3[dt$Es=="GRC_1990"]

dt$Ll.1[dt$Es=="GRC_1996"]=dt$RSYML1[dt$Es=="GRC_1996"]
dt$Ll.2[dt$Es=="GRC_1996"]=dt$RSYML2[dt$Es=="GRC_1996"]
dt$Ll.3[dt$Es=="GRC_1996"]=dt$RSYML3[dt$Es=="GRC_1996"]
dt$Ll.4[dt$Es=="GRC_1996"]=dt$RSYML4[dt$Es=="GRC_1996"]
dt$Ll.5[dt$Es=="GRC_1996"]=dt$RSYML5[dt$Es=="GRC_1996"]

dt$Ll.1[dt$Es=="GRC_2000"]=dt$RSYML1[dt$Es=="GRC_2000"]
dt$Ll.2[dt$Es=="GRC_2000"]=dt$RSYML2[dt$Es=="GRC_2000"]
dt$Ll.3[dt$Es=="GRC_2000"]=dt$RSYML3[dt$Es=="GRC_2000"]
dt$Ll.4[dt$Es=="GRC_2000"]=dt$RSYML4[dt$Es=="GRC_2000"]

dt$Ll.1[dt$Es=="GRC_2004"]=dt$RSYML1[dt$Es=="GRC_2004"]
dt$Ll.2[dt$Es=="GRC_2004"]=dt$RSYML2[dt$Es=="GRC_2004"]
dt$Ll.3[dt$Es=="GRC_2004"]=dt$RSYML3[dt$Es=="GRC_2004"]
dt$Ll.4[dt$Es=="GRC_2004"]=dt$RSYML4[dt$Es=="GRC_2004"]

dt$Ll.1[dt$Es=="GRC_2007"]=dt$RSYML1[dt$Es=="GRC_2007"]
dt$Ll.2[dt$Es=="GRC_2007"]=dt$RSYML2[dt$Es=="GRC_2007"]
dt$Ll.3[dt$Es=="GRC_2007"]=dt$RSYML3[dt$Es=="GRC_2007"]
dt$Ll.4[dt$Es=="GRC_2007"]=dt$RSYML4[dt$Es=="GRC_2007"]
dt$Ll.5[dt$Es=="GRC_2007"]=dt$RSYML5[dt$Es=="GRC_2007"]

dt$Ll.1[dt$Es=="HUN_1998"]=dt$RSYML1[dt$Es=="HUN_1998"]
dt$Ll.2[dt$Es=="HUN_1998"]=dt$RSYML5[dt$Es=="HUN_1998"]
dt$Ll.3[dt$Es=="HUN_1998"]=dt$RSYML2[dt$Es=="HUN_1998"]
dt$Ll.4[dt$Es=="HUN_1998"]=dt$RSYML6[dt$Es=="HUN_1998"]
dt$Ll.5[dt$Es=="HUN_1998"]=dt$RSYML4[dt$Es=="HUN_1998"]
dt$Ll.6[dt$Es=="HUN_1998"]=dt$RSYML3[dt$Es=="HUN_1998"]

dt$Ll.1[dt$Es=="HUN_2006"]=dt$RSYML1[dt$Es=="HUN_2006"]
dt$Ll.2[dt$Es=="HUN_2006"]=dt$RSYML2[dt$Es=="HUN_2006"]
dt$Ll.3[dt$Es=="HUN_2006"]=dt$RSYML3[dt$Es=="HUN_2006"]
dt$Ll.4[dt$Es=="HUN_2006"]=dt$RSYML4[dt$Es=="HUN_2006"]

dt$Ll.1[dt$Es=="IRL_2002"]=dt$RSYML1[dt$Es=="IRL_2002"]
dt$Ll.2[dt$Es=="IRL_2002"]=dt$RSYML2[dt$Es=="IRL_2002"]
dt$Ll.3[dt$Es=="IRL_2002"]=dt$RSYML4[dt$Es=="IRL_2002"]
dt$Ll.4[dt$Es=="IRL_2002"]=dt$RSYML5[dt$Es=="IRL_2002"]
dt$Ll.5[dt$Es=="IRL_2002"]=dt$RSYML3[dt$Es=="IRL_2002"]
dt$Ll.6[dt$Es=="IRL_2002"]=dt$RSYML6[dt$Es=="IRL_2002"]

dt$Ll.1[dt$Es=="ISL_1987"]=dt$RSYML3[dt$Es=="ISL_1987"]
dt$Ll.2[dt$Es=="ISL_1987"]=dt$RSYML2[dt$Es=="ISL_1987"]
dt$Ll.3[dt$Es=="ISL_1987"]=dt$RSYML1[dt$Es=="ISL_1987"]
dt$Ll.4[dt$Es=="ISL_1987"]=dt$RSYML4[dt$Es=="ISL_1987"]
dt$Ll.5[dt$Es=="ISL_1987"]=dt$RSYML5[dt$Es=="ISL_1987"]

dt$Ll.1[dt$Es=="ISL_1991"]=dt$RSYML3[dt$Es=="ISL_1991"]
dt$Ll.2[dt$Es=="ISL_1991"]=dt$RSYML2[dt$Es=="ISL_1991"]
dt$Ll.3[dt$Es=="ISL_1991"]=dt$RSYML1[dt$Es=="ISL_1991"]
dt$Ll.4[dt$Es=="ISL_1991"]=dt$RSYML4[dt$Es=="ISL_1991"]
dt$Ll.5[dt$Es=="ISL_1991"]=dt$RSYML5[dt$Es=="ISL_1991"]

dt$Ll.1[dt$Es=="ISL_1995"]=dt$RSYML3[dt$Es=="ISL_1995"]
dt$Ll.2[dt$Es=="ISL_1995"]=dt$RSYML2[dt$Es=="ISL_1995"]
dt$Ll.3[dt$Es=="ISL_1995"]=dt$RSYML4[dt$Es=="ISL_1995"]
dt$Ll.4[dt$Es=="ISL_1995"]=dt$RSYML1[dt$Es=="ISL_1995"]
dt$Ll.5[dt$Es=="ISL_1995"]=dt$RSYML5[dt$Es=="ISL_1995"]
dt$Ll.6[dt$Es=="ISL_1995"]=dt$RSYML6[dt$Es=="ISL_1995"]

dt$Ll.1[dt$Es=="ISL_2003"]=dt$RSYML3[dt$Es=="ISL_2003"]
dt$Ll.2[dt$Es=="ISL_2003"]=dt$RSYML1[dt$Es=="ISL_2003"]
dt$Ll.3[dt$Es=="ISL_2003"]=dt$RSYML2[dt$Es=="ISL_2003"]
dt$Ll.4[dt$Es=="ISL_2003"]=dt$RSYML4[dt$Es=="ISL_2003"]
dt$Ll.5[dt$Es=="ISL_2003"]=dt$RSYML5[dt$Es=="ISL_2003"]

dt$Ll.1[dt$Es=="ITA_2006"]=dt$RSYML3[dt$Es=="ITA_2006"]#coalition==1
dt$Ll.2[dt$Es=="ITA_2006"]=dt$RSYML5[dt$Es=="ITA_2006"]
dt$Ll.3[dt$Es=="ITA_2006"]=dt$RSYML6[dt$Es=="ITA_2006"]
dt$Ll.4[dt$Es=="ITA_2006"]=dt$RSYML4[dt$Es=="ITA_2006"]
dt$Ll.5[dt$Es=="ITA_2006"]=dt$RSYML1[dt$Es=="ITA_2006"]
dt$Ll.6[dt$Es=="ITA_2006"]=dt$RSYML7[dt$Es=="ITA_2006"]

dt$Ll.1[dt$Es=="ITA_2008"]=dt$RSYML4[dt$Es=="ITA_2008"]#coalition==1
dt$Ll.2[dt$Es=="ITA_2008"]=dt$RSYML2[dt$Es=="ITA_2008"]
dt$Ll.3[dt$Es=="ITA_2008"]=dt$RSYML5[dt$Es=="ITA_2008"]
dt$Ll.4[dt$Es=="ITA_2008"]=dt$RSYML6[dt$Es=="ITA_2008"]
dt$Ll.5[dt$Es=="ITA_2008"]=dt$RSYML3[dt$Es=="ITA_2008"]
dt$Ll.6[dt$Es=="ITA_2008"]=dt$RSYML1[dt$Es=="ITA_2008"]

dt$Ll.1[dt$Es=="LTU_2000"]=dt$RSYML2[dt$Es=="LTU_2000"]
dt$Ll.2[dt$Es=="LTU_2000"]=dt$RSYML3[dt$Es=="LTU_2000"]
dt$Ll.3[dt$Es=="LTU_2000"]=dt$RSYML4[dt$Es=="LTU_2000"]
dt$Ll.4[dt$Es=="LTU_2000"]=dt$RSYML1[dt$Es=="LTU_2000"]

dt$Ll.1[dt$Es=="NLD_2002"]=dt$RSYML2[dt$Es=="NLD_2002"]
dt$Ll.2[dt$Es=="NLD_2002"]=dt$RSYML6[dt$Es=="NLD_2002"]
dt$Ll.3[dt$Es=="NLD_2002"]=dt$RSYML3[dt$Es=="NLD_2002"]
dt$Ll.4[dt$Es=="NLD_2002"]=dt$RSYML1[dt$Es=="NLD_2002"]
dt$Ll.5[dt$Es=="NLD_2002"]=dt$RSYML5[dt$Es=="NLD_2002"]
dt$Ll.6[dt$Es=="NLD_2002"]=dt$RSYML7[dt$Es=="NLD_2002"]

dt$Ll.1[dt$Es=="NOR_2001"]=dt$RSYML2[dt$Es=="NOR_2001"]
dt$Ll.2[dt$Es=="NOR_2001"]=dt$RSYML6[dt$Es=="NOR_2001"]
dt$Ll.3[dt$Es=="NOR_2001"]=dt$RSYML7[dt$Es=="NOR_2001"]
dt$Ll.4[dt$Es=="NOR_2001"]=dt$RSYML1[dt$Es=="NOR_2001"]
dt$Ll.5[dt$Es=="NOR_2001"]=dt$RSYML4[dt$Es=="NOR_2001"]
dt$Ll.6[dt$Es=="NOR_2001"]=dt$RSYML5[dt$Es=="NOR_2001"]

dt$Ll.1[dt$Es=="PRT_2005"]=dt$RSYML5[dt$Es=="PRT_2005"]
dt$Ll.2[dt$Es=="PRT_2005"]=dt$RSYML4[dt$Es=="PRT_2005"]
dt$Ll.3[dt$Es=="PRT_2005"]=dt$RSYML3[dt$Es=="PRT_2005"]
dt$Ll.4[dt$Es=="PRT_2005"]=dt$RSYML2[dt$Es=="PRT_2005"]
dt$Ll.5[dt$Es=="PRT_2005"]=dt$RSYML1[dt$Es=="PRT_2005"]

dt$Ll.1[dt$Es=="SVN_2000"]=dt$RSYML2[dt$Es=="SVN_2000"]
dt$Ll.2[dt$Es=="SVN_2000"]=dt$RSYML5[dt$Es=="SVN_2000"]
dt$Ll.3[dt$Es=="SVN_2000"]=dt$RSYML7[dt$Es=="SVN_2000"]
dt$Ll.4[dt$Es=="SVN_2000"]=dt$RSYML3[dt$Es=="SVN_2000"]
dt$Ll.5[dt$Es=="SVN_2000"]=dt$RSYML6[dt$Es=="SVN_2000"]
dt$Ll.6[dt$Es=="SVN_2000"]=dt$RSYML1[dt$Es=="SVN_2000"]

dt$Ll.1[dt$Es=="SWE_1979"]=dt$RSYML2[dt$Es=="SWE_1979"]
dt$Ll.2[dt$Es=="SWE_1979"]=dt$RSYML5[dt$Es=="SWE_1979"]
dt$Ll.3[dt$Es=="SWE_1979"]=dt$RSYML3[dt$Es=="SWE_1979"]
dt$Ll.4[dt$Es=="SWE_1979"]=dt$RSYML4[dt$Es=="SWE_1979"]
dt$Ll.5[dt$Es=="SWE_1979"]=dt$RSYML1[dt$Es=="SWE_1979"]

dt$Ll.1[dt$Es=="SWE_2002"]=dt$RSYML2[dt$Es=="SWE_2002"]
dt$Ll.2[dt$Es=="SWE_2002"]=dt$RSYML5[dt$Es=="SWE_2002"]
dt$Ll.3[dt$Es=="SWE_2002"]=dt$RSYML4[dt$Es=="SWE_2002"]
dt$Ll.4[dt$Es=="SWE_2002"]=dt$RSYML6[dt$Es=="SWE_2002"]
dt$Ll.5[dt$Es=="SWE_2002"]=dt$RSYML1[dt$Es=="SWE_2002"]
dt$Ll.6[dt$Es=="SWE_2002"]=dt$RSYML3[dt$Es=="SWE_2002"]

dt$Ll.1[dt$Es=="SWE_2010"]=dt$RSYML2[dt$Es=="SWE_2010"]
dt$Ll.2[dt$Es=="SWE_2010"]=dt$RSYML5[dt$Es=="SWE_2010"]
dt$Ll.3[dt$Es=="SWE_2010"]=dt$RSYML7[dt$Es=="SWE_2010"]
dt$Ll.4[dt$Es=="SWE_2010"]=dt$RSYML4[dt$Es=="SWE_2010"]
dt$Ll.5[dt$Es=="SWE_2010"]=dt$RSYML3[dt$Es=="SWE_2010"]
dt$Ll.6[dt$Es=="SWE_2010"]=dt$RSYML10[dt$Es=="SWE_2010"]

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$Ll.1[dt$Es=="DEU_1961"]=dt$RSYML2[dt$Es=="DEU_1961"]
dt$Ll.2[dt$Es=="DEU_1961"]=dt$RSYML1[dt$Es=="DEU_1961"]
dt$Ll.3[dt$Es=="DEU_1961"]=dt$RSYML3[dt$Es=="DEU_1961"]

dt$Ll.1[dt$Es=="DEU_1965"]=dt$RSYML2[dt$Es=="DEU_1965"]
dt$Ll.2[dt$Es=="DEU_1965"]=dt$RSYML1[dt$Es=="DEU_1965"]
dt$Ll.3[dt$Es=="DEU_1965"]=dt$RSYML3[dt$Es=="DEU_1965"]

dt$Ll.1[dt$Es=="DEU_1976"]=dt$RSYML2[dt$Es=="DEU_1976"]
dt$Ll.2[dt$Es=="DEU_1976"]=dt$RSYML1[dt$Es=="DEU_1976"]
dt$Ll.3[dt$Es=="DEU_1976"]=dt$RSYML3[dt$Es=="DEU_1976"]

dt$Ll.1[dt$Es=="DEU_1980"]=dt$RSYML2[dt$Es=="DEU_1980"]
dt$Ll.2[dt$Es=="DEU_1980"]=dt$RSYML1[dt$Es=="DEU_1980"]
dt$Ll.3[dt$Es=="DEU_1980"]=dt$RSYML3[dt$Es=="DEU_1980"]

dt$Ll.1[dt$Es=="DEU_1983"]=dt$RSYML2[dt$Es=="DEU_1983"]
dt$Ll.2[dt$Es=="DEU_1983"]=dt$RSYML1[dt$Es=="DEU_1983"]
dt$Ll.3[dt$Es=="DEU_1983"]=dt$RSYML3[dt$Es=="DEU_1983"]

dt$Ll.1[dt$Es=="DEU_1987"]=dt$RSYML2[dt$Es=="DEU_1987"]
dt$Ll.2[dt$Es=="DEU_1987"]=dt$RSYML1[dt$Es=="DEU_1987"]
dt$Ll.3[dt$Es=="DEU_1987"]=dt$RSYML3[dt$Es=="DEU_1987"]

dt$Ll.1[dt$Es=="DEU_1990"]=dt$RSYML2[dt$Es=="DEU_1990"]
dt$Ll.2[dt$Es=="DEU_1990"]=dt$RSYML1[dt$Es=="DEU_1990"]
dt$Ll.3[dt$Es=="DEU_1990"]=dt$RSYML3[dt$Es=="DEU_1990"]
dt$Ll.4[dt$Es=="DEU_1990"]=dt$RSYML5[dt$Es=="DEU_1990"]

dt$Ll.1[dt$Es=="DEU_1994"]=dt$RSYML2[dt$Es=="DEU_1994"]
dt$Ll.2[dt$Es=="DEU_1994"]=dt$RSYML1[dt$Es=="DEU_1994"]
dt$Ll.3[dt$Es=="DEU_1994"]=dt$RSYML4[dt$Es=="DEU_1994"]
dt$Ll.4[dt$Es=="DEU_1994"]=dt$RSYML3[dt$Es=="DEU_1994"]
dt$Ll.5[dt$Es=="DEU_1994"]=dt$RSYML5[dt$Es=="DEU_1994"]

dt$Ll.1[dt$Es=="DEU_1998"]=dt$RSYML1[dt$Es=="DEU_1998"]
dt$Ll.2[dt$Es=="DEU_1998"]=dt$RSYML2[dt$Es=="DEU_1998"]
dt$Ll.3[dt$Es=="DEU_1998"]=dt$RSYML4[dt$Es=="DEU_1998"]
dt$Ll.4[dt$Es=="DEU_1998"]=dt$RSYML3[dt$Es=="DEU_1998"]
dt$Ll.5[dt$Es=="DEU_1998"]=dt$RSYML5[dt$Es=="DEU_1998"]

dt$Ll.1[dt$Es=="DEU_2009"]=dt$RSYML2[dt$Es=="DEU_2009"]
dt$Ll.2[dt$Es=="DEU_2009"]=dt$RSYML1[dt$Es=="DEU_2009"]
dt$Ll.3[dt$Es=="DEU_2009"]=dt$RSYML3[dt$Es=="DEU_2009"]
dt$Ll.4[dt$Es=="DEU_2009"]=dt$RSYML5[dt$Es=="DEU_2009"]
dt$Ll.5[dt$Es=="DEU_2009"]=dt$RSYML4[dt$Es=="DEU_2009"]

dt$Ll.1[dt$Es=="DEU_2013"]=dt$RSYML2[dt$Es=="DEU_2013"]
dt$Ll.2[dt$Es=="DEU_2013"]=dt$RSYML1[dt$Es=="DEU_2013"]
dt$Ll.3[dt$Es=="DEU_2013"]=dt$RSYML5[dt$Es=="DEU_2013"]
dt$Ll.4[dt$Es=="DEU_2013"]=dt$RSYML4[dt$Es=="DEU_2013"]
dt$Ll.5[dt$Es=="DEU_2013"]=dt$RSYML3[dt$Es=="DEU_2013"]

dt$Ll.1[dt$Es=="FIN_2007"]=dt$RSYML1[dt$Es=="FIN_2007"]
dt$Ll.2[dt$Es=="FIN_2007"]=dt$RSYML3[dt$Es=="FIN_2007"]
dt$Ll.3[dt$Es=="FIN_2007"]=dt$RSYML2[dt$Es=="FIN_2007"]
dt$Ll.4[dt$Es=="FIN_2007"]=dt$RSYML4[dt$Es=="FIN_2007"]
dt$Ll.5[dt$Es=="FIN_2007"]=dt$RSYML5[dt$Es=="FIN_2007"]
dt$Ll.6[dt$Es=="FIN_2007"]=dt$RSYML7[dt$Es=="FIN_2007"]

dt$Ll.1[dt$Es=="FIN_2011"]=dt$RSYML3[dt$Es=="FIN_2011"]
dt$Ll.2[dt$Es=="FIN_2011"]=dt$RSYML2[dt$Es=="FIN_2011"]
dt$Ll.3[dt$Es=="FIN_2011"]=dt$RSYML8[dt$Es=="FIN_2011"]
dt$Ll.4[dt$Es=="FIN_2011"]=dt$RSYML1[dt$Es=="FIN_2011"]
dt$Ll.5[dt$Es=="FIN_2011"]=dt$RSYML4[dt$Es=="FIN_2011"]
dt$Ll.6[dt$Es=="FIN_2011"]=dt$RSYML5[dt$Es=="FIN_2011"]

dt$Ll.1[dt$Es=="GRC_2009"]=dt$RSYML1[dt$Es=="GRC_2009"]
dt$Ll.2[dt$Es=="GRC_2009"]=dt$RSYML2[dt$Es=="GRC_2009"]
dt$Ll.3[dt$Es=="GRC_2009"]=dt$RSYML3[dt$Es=="GRC_2009"]
dt$Ll.4[dt$Es=="GRC_2009"]=dt$RSYML4[dt$Es=="GRC_2009"]
dt$Ll.5[dt$Es=="GRC_2009"]=dt$RSYML5[dt$Es=="GRC_2009"]
dt$Ll.6[dt$Es=="GRC_2009"]=dt$RSYML6[dt$Es=="GRC_2009"]

dt$Ll.1[dt$Es=="GRC_2012"]=dt$RSYML1[dt$Es=="GRC_2012"]
dt$Ll.2[dt$Es=="GRC_2012"]=dt$RSYML2[dt$Es=="GRC_2012"]
dt$Ll.3[dt$Es=="GRC_2012"]=dt$RSYML3[dt$Es=="GRC_2012"]
dt$Ll.4[dt$Es=="GRC_2012"]=dt$RSYML4[dt$Es=="GRC_2012"]
dt$Ll.5[dt$Es=="GRC_2012"]=dt$RSYML5[dt$Es=="GRC_2012"]
dt$Ll.6[dt$Es=="GRC_2012"]=dt$RSYML6[dt$Es=="GRC_2012"]

dt$Ll.1[dt$Es=="IRL_2007"]=dt$RSYML1[dt$Es=="IRL_2007"]
dt$Ll.2[dt$Es=="IRL_2007"]=dt$RSYML2[dt$Es=="IRL_2007"]
dt$Ll.3[dt$Es=="IRL_2007"]=dt$RSYML4[dt$Es=="IRL_2007"]
dt$Ll.4[dt$Es=="IRL_2007"]=dt$RSYML3[dt$Es=="IRL_2007"]
dt$Ll.5[dt$Es=="IRL_2007"]=dt$RSYML6[dt$Es=="IRL_2007"]
dt$Ll.6[dt$Es=="IRL_2007"]=dt$RSYML5[dt$Es=="IRL_2007"]

dt$Ll.1[dt$Es=="IRL_2011"]=dt$RSYML2[dt$Es=="IRL_2011"]
dt$Ll.2[dt$Es=="IRL_2011"]=dt$RSYML3[dt$Es=="IRL_2011"]
dt$Ll.3[dt$Es=="IRL_2011"]=dt$RSYML1[dt$Es=="IRL_2011"]
dt$Ll.4[dt$Es=="IRL_2011"]=dt$RSYML4[dt$Es=="IRL_2011"]
dt$Ll.5[dt$Es=="IRL_2011"]=dt$RSYML5[dt$Es=="IRL_2011"]#

dt$Ll.1[dt$Es=="ISL_1999"]=dt$RSYML3[dt$Es=="ISL_1999"]
dt$Ll.2[dt$Es=="ISL_1999"]=dt$RSYML1[dt$Es=="ISL_1999"]
dt$Ll.3[dt$Es=="ISL_1999"]=dt$RSYML2[dt$Es=="ISL_1999"]
dt$Ll.4[dt$Es=="ISL_1999"]=dt$RSYML4[dt$Es=="ISL_1999"]
dt$Ll.5[dt$Es=="ISL_1999"]=dt$RSYML5[dt$Es=="ISL_1999"]

dt$Ll.1[dt$Es=="ISL_2007"]=dt$RSYML3[dt$Es=="ISL_2007"]
dt$Ll.2[dt$Es=="ISL_2007"]=dt$RSYML1[dt$Es=="ISL_2007"]
dt$Ll.3[dt$Es=="ISL_2007"]=dt$RSYML4[dt$Es=="ISL_2007"]
dt$Ll.4[dt$Es=="ISL_2007"]=dt$RSYML2[dt$Es=="ISL_2007"]
dt$Ll.5[dt$Es=="ISL_2007"]=dt$RSYML5[dt$Es=="ISL_2007"]
dt$Ll.6[dt$Es=="ISL_2007"]=dt$RSYML6[dt$Es=="ISL_2007"]#

dt$Ll.1[dt$Es=="ISL_2009"]=dt$RSYML1[dt$Es=="ISL_2009"]
dt$Ll.2[dt$Es=="ISL_2009"]=dt$RSYML3[dt$Es=="ISL_2009"]
dt$Ll.3[dt$Es=="ISL_2009"]=dt$RSYML4[dt$Es=="ISL_2009"]
dt$Ll.4[dt$Es=="ISL_2009"]=dt$RSYML2[dt$Es=="ISL_2009"]
dt$Ll.5[dt$Es=="ISL_2009"]=dt$RSYML5[dt$Es=="ISL_2009"]#
dt$Ll.6[dt$Es=="ISL_2009"]=dt$RSYML6[dt$Es=="ISL_2009"]#

dt$Ll.1[dt$Es=="ISL_2013"]=dt$RSYML3[dt$Es=="ISL_2013"]
dt$Ll.2[dt$Es=="ISL_2013"]=dt$RSYML2[dt$Es=="ISL_2013"]
dt$Ll.3[dt$Es=="ISL_2013"]=dt$RSYML1[dt$Es=="ISL_2013"]
dt$Ll.4[dt$Es=="ISL_2013"]=dt$RSYML4[dt$Es=="ISL_2013"]
dt$Ll.5[dt$Es=="ISL_2013"]=dt$RSYML5[dt$Es=="ISL_2013"]
dt$Ll.6[dt$Es=="ISL_2013"]=dt$RSYML6[dt$Es=="ISL_2013"]

dt$Ll.1[dt$Es=="NLD_1994"]=dt$RSYML1[dt$Es=="NLD_1994"]
dt$Ll.2[dt$Es=="NLD_1994"]=dt$RSYML2[dt$Es=="NLD_1994"]
dt$Ll.3[dt$Es=="NLD_1994"]=dt$RSYML3[dt$Es=="NLD_1994"]
dt$Ll.4[dt$Es=="NLD_1994"]=dt$RSYML4[dt$Es=="NLD_1994"]

dt$Ll.1[dt$Es=="NLD_1998"]=dt$RSYML1[dt$Es=="NLD_1998"]#EV 4 parties, CSES 6 parties coded
dt$Ll.2[dt$Es=="NLD_1998"]=dt$RSYML3[dt$Es=="NLD_1998"]
dt$Ll.3[dt$Es=="NLD_1998"]=dt$RSYML2[dt$Es=="NLD_1998"]
dt$Ll.4[dt$Es=="NLD_1998"]=dt$RSYML4[dt$Es=="NLD_1998"]
dt$Ll.5[dt$Es=="NLD_1998"]=dt$RSYML5[dt$Es=="NLD_1998"]
dt$Ll.6[dt$Es=="NLD_1998"]=dt$RSYML7[dt$Es=="NLD_1998"]#

dt$Ll.1[dt$Es=="NOR_1981"]=dt$RSYML2[dt$Es=="NOR_1981"]
dt$Ll.2[dt$Es=="NOR_1981"]=dt$RSYML6[dt$Es=="NOR_1981"]
dt$Ll.3[dt$Es=="NOR_1981"]=dt$RSYML4[dt$Es=="NOR_1981"]
dt$Ll.4[dt$Es=="NOR_1981"]=dt$RSYML5[dt$Es=="NOR_1981"]
dt$Ll.5[dt$Es=="NOR_1981"]=dt$RSYML1[dt$Es=="NOR_1981"]
dt$Ll.6[dt$Es=="NOR_1981"]=dt$RSYML7[dt$Es=="NOR_1981"]

dt$Ll.1[dt$Es=="NOR_1985"]=dt$RSYML2[dt$Es=="NOR_1985"]
dt$Ll.2[dt$Es=="NOR_1985"]=dt$RSYML6[dt$Es=="NOR_1985"]
dt$Ll.3[dt$Es=="NOR_1985"]=dt$RSYML4[dt$Es=="NOR_1985"]
dt$Ll.4[dt$Es=="NOR_1985"]=dt$RSYML5[dt$Es=="NOR_1985"]
dt$Ll.5[dt$Es=="NOR_1985"]=dt$RSYML1[dt$Es=="NOR_1985"]
dt$Ll.6[dt$Es=="NOR_1985"]=dt$RSYML7[dt$Es=="NOR_1985"]

dt$Ll.1[dt$Es=="NOR_1989"]=dt$RSYML2[dt$Es=="NOR_1989"]
dt$Ll.2[dt$Es=="NOR_1989"]=dt$RSYML6[dt$Es=="NOR_1989"]
dt$Ll.3[dt$Es=="NOR_1989"]=dt$RSYML7[dt$Es=="NOR_1989"]
dt$Ll.4[dt$Es=="NOR_1989"]=dt$RSYML1[dt$Es=="NOR_1989"]
dt$Ll.5[dt$Es=="NOR_1989"]=dt$RSYML4[dt$Es=="NOR_1989"]
dt$Ll.6[dt$Es=="NOR_1989"]=dt$RSYML5[dt$Es=="NOR_1989"]

dt$Ll.1[dt$Es=="NOR_1993"]=dt$RSYML2[dt$Es=="NOR_1993"]
dt$Ll.2[dt$Es=="NOR_1993"]=dt$RSYML5[dt$Es=="NOR_1993"]
dt$Ll.3[dt$Es=="NOR_1993"]=dt$RSYML6[dt$Es=="NOR_1993"]
dt$Ll.4[dt$Es=="NOR_1993"]=dt$RSYML1[dt$Es=="NOR_1993"]
dt$Ll.5[dt$Es=="NOR_1993"]=dt$RSYML4[dt$Es=="NOR_1993"]
dt$Ll.6[dt$Es=="NOR_1993"]=dt$RSYML7[dt$Es=="NOR_1993"]

dt$Ll.1[dt$Es=="NOR_1997"]=dt$RSYML2[dt$Es=="NOR_1997"]
dt$Ll.2[dt$Es=="NOR_1997"]=dt$RSYML7[dt$Es=="NOR_1997"]
dt$Ll.3[dt$Es=="NOR_1997"]=dt$RSYML4[dt$Es=="NOR_1997"]
dt$Ll.4[dt$Es=="NOR_1997"]=dt$RSYML6[dt$Es=="NOR_1997"]
dt$Ll.5[dt$Es=="NOR_1997"]=dt$RSYML5[dt$Es=="NOR_1997"]
dt$Ll.6[dt$Es=="NOR_1997"]=dt$RSYML1[dt$Es=="NOR_1997"]

dt$Ll.1[dt$Es=="NOR_2005"]=dt$RSYML2[dt$Es=="NOR_2005"]
dt$Ll.2[dt$Es=="NOR_2005"]=dt$RSYML7[dt$Es=="NOR_2005"]
dt$Ll.3[dt$Es=="NOR_2005"]=dt$RSYML6[dt$Es=="NOR_2005"]
dt$Ll.4[dt$Es=="NOR_2005"]=dt$RSYML1[dt$Es=="NOR_2005"]
dt$Ll.5[dt$Es=="NOR_2005"]=dt$RSYML4[dt$Es=="NOR_2005"]
dt$Ll.6[dt$Es=="NOR_2005"]=dt$RSYML5[dt$Es=="NOR_2005"]

dt$Ll.1[dt$Es=="PRT_2002"]=dt$RSYML4[dt$Es=="PRT_2002"]
dt$Ll.2[dt$Es=="PRT_2002"]=dt$RSYML5[dt$Es=="PRT_2002"]
dt$Ll.3[dt$Es=="PRT_2002"]=dt$RSYML2[dt$Es=="PRT_2002"]
dt$Ll.4[dt$Es=="PRT_2002"]=dt$RSYML3[dt$Es=="PRT_2002"]
dt$Ll.5[dt$Es=="PRT_2002"]=dt$RSYML1[dt$Es=="PRT_2002"]
dt$Ll.6[dt$Es=="PRT_2002"]=dt$RSYML6[dt$Es=="PRT_2002"]

dt$Ll.1[dt$Es=="PRT_2009"]=dt$RSYML5[dt$Es=="PRT_2009"]#osym4-5  inverted!?
dt$Ll.2[dt$Es=="PRT_2009"]=dt$RSYML4[dt$Es=="PRT_2009"]
dt$Ll.3[dt$Es=="PRT_2009"]=dt$RSYML2[dt$Es=="PRT_2009"]
dt$Ll.4[dt$Es=="PRT_2009"]=dt$RSYML1[dt$Es=="PRT_2009"]
dt$Ll.5[dt$Es=="PRT_2009"]=dt$RSYML3[dt$Es=="PRT_2009"]

dt$Ll.1[dt$Es=="SWE_1982"]=dt$RSYML2[dt$Es=="SWE_1982"]
dt$Ll.2[dt$Es=="SWE_1982"]=dt$RSYML5[dt$Es=="SWE_1982"]
dt$Ll.3[dt$Es=="SWE_1982"]=dt$RSYML3[dt$Es=="SWE_1982"]
dt$Ll.4[dt$Es=="SWE_1982"]=dt$RSYML4[dt$Es=="SWE_1982"]
dt$Ll.5[dt$Es=="SWE_1982"]=dt$RSYML1[dt$Es=="SWE_1982"]

dt$Ll.1[dt$Es=="SWE_1985"]=dt$RSYML2[dt$Es=="SWE_1985"]
dt$Ll.2[dt$Es=="SWE_1985"]=dt$RSYML5[dt$Es=="SWE_1985"]
dt$Ll.3[dt$Es=="SWE_1985"]=dt$RSYML4[dt$Es=="SWE_1985"]
dt$Ll.4[dt$Es=="SWE_1985"]=dt$RSYML3[dt$Es=="SWE_1985"]
dt$Ll.5[dt$Es=="SWE_1985"]=dt$RSYML1[dt$Es=="SWE_1985"]
dt$Ll.6[dt$Es=="SWE_1985"]=dt$RSYML6[dt$Es=="SWE_1985"]

dt$Ll.1[dt$Es=="SWE_1988"]=dt$RSYML2[dt$Es=="SWE_1988"]
dt$Ll.2[dt$Es=="SWE_1988"]=dt$RSYML5[dt$Es=="SWE_1988"]
dt$Ll.3[dt$Es=="SWE_1988"]=dt$RSYML4[dt$Es=="SWE_1988"]
dt$Ll.4[dt$Es=="SWE_1988"]=dt$RSYML3[dt$Es=="SWE_1988"]
dt$Ll.5[dt$Es=="SWE_1988"]=dt$RSYML1[dt$Es=="SWE_1988"]

dt$Ll.1[dt$Es=="SWE_1991"]=dt$RSYML2[dt$Es=="SWE_1991"]
dt$Ll.2[dt$Es=="SWE_1991"]=dt$RSYML5[dt$Es=="SWE_1991"]
dt$Ll.3[dt$Es=="SWE_1991"]=dt$RSYML4[dt$Es=="SWE_1991"]
dt$Ll.4[dt$Es=="SWE_1991"]=dt$RSYML3[dt$Es=="SWE_1991"]
dt$Ll.5[dt$Es=="SWE_1991"]=dt$RSYML6[dt$Es=="SWE_1991"]
dt$Ll.6[dt$Es=="SWE_1991"]=dt$RSYML9[dt$Es=="SWE_1991"]

dt$Ll.1[dt$Es=="SWE_1994"]=dt$RSYML2[dt$Es=="SWE_1994"]
dt$Ll.2[dt$Es=="SWE_1994"]=dt$RSYML5[dt$Es=="SWE_1994"]
dt$Ll.3[dt$Es=="SWE_1994"]=dt$RSYML3[dt$Es=="SWE_1994"]
dt$Ll.4[dt$Es=="SWE_1994"]=dt$RSYML4[dt$Es=="SWE_1994"]
dt$Ll.5[dt$Es=="SWE_1994"]=dt$RSYML1[dt$Es=="SWE_1994"]
dt$Ll.6[dt$Es=="SWE_1994"]=dt$RSYML7[dt$Es=="SWE_1994"]

dt$Ll.1[dt$Es=="SWE_1998"]=dt$RSYML2[dt$Es=="SWE_1998"]
dt$Ll.2[dt$Es=="SWE_1998"]=dt$RSYML5[dt$Es=="SWE_1998"]
dt$Ll.3[dt$Es=="SWE_1998"]=dt$RSYML1[dt$Es=="SWE_1998"]
dt$Ll.4[dt$Es=="SWE_1998"]=dt$RSYML6[dt$Es=="SWE_1998"]
dt$Ll.5[dt$Es=="SWE_1998"]=dt$RSYML3[dt$Es=="SWE_1998"]
dt$Ll.6[dt$Es=="SWE_1998"]=dt$RSYML4[dt$Es=="SWE_1998"]

dt$Ll.1[dt$Es=="SWE_2006"]=dt$RSYML2[dt$Es=="SWE_2006"]
dt$Ll.2[dt$Es=="SWE_2006"]=dt$RSYML5[dt$Es=="SWE_2006"]
dt$Ll.3[dt$Es=="SWE_2006"]=dt$RSYML3[dt$Es=="SWE_2006"]
dt$Ll.4[dt$Es=="SWE_2006"]=dt$RSYML4[dt$Es=="SWE_2006"]
dt$Ll.5[dt$Es=="SWE_2006"]=dt$RSYML6[dt$Es=="SWE_2006"]
dt$Ll.6[dt$Es=="SWE_2006"]=dt$RSYML1[dt$Es=="SWE_2006"]


dt$Ll.1=as.numeric(dt$Ll.1)#recode as numeric:
dt$Ll.2=as.numeric(dt$Ll.2)
dt$Ll.3=as.numeric(dt$Ll.3)
dt$Ll.4=as.numeric(dt$Ll.4)
dt$Ll.5=as.numeric(dt$Ll.5)
dt$Ll.6=as.numeric(dt$Ll.6)

dt$Ll.1[dt$Ll.1>1]=NA#exclude NAs coded 900s:
dt$Ll.2[dt$Ll.2>1]=NA
dt$Ll.3[dt$Ll.3>1]=NA
dt$Ll.4[dt$Ll.4>1]=NA
dt$Ll.5[dt$Ll.5>1]=NA
dt$Ll.6[dt$Ll.6>1]=NA

dt$Ll.1=dt$Ll.1*10#recode to 0-10 scale:
dt$Ll.2=dt$Ll.2*10
dt$Ll.3=dt$Ll.3*10
dt$Ll.4=dt$Ll.4*10
dt$Ll.5=dt$Ll.5*10
dt$Ll.6=dt$Ll.6*10

#subset:----

#keep only respondents (and elections) with coded Pl,Ll:
# (I keep here elections with at least one party coded for either Pl or Ll, which is the same)
Pl=dt[, names(dt) %in% c(paste0("Pl.", 1:14))]#create matrix Pl data
Pl=as.matrix(Pl)
dt=dt[dt$Es %in% c(unique(dt$Es[rowMins(Pl, na.rm=T)<20])),]#keep only Es with Pl for at least one party
Ll=dt[, names(dt) %in% c(paste0("Ll.", 1:14))]#create matrix Ll data
Ll=as.matrix(Ll)
dt=dt[dt$Es %in% c(unique(dt$Es[rowMins(Ll, na.rm=T)<20])),]#keep only Es with Ll for at least one party
rm(Pl,Ll)

#get rid of elections with less than three parties and/or leaders coded:
# (already excluded GRC_1989j)
dt=dt[!(dt$Es %in% c("DEU_1972","DEU_2002","GRC_1993","ITA_2013","PRT_1985")),]

#get rid of elections non free Freedom House:
dt=dt[!(dt$Es %in% c("TUR_2007","TUR_2011")),]

#exclude presidential systems:
dew=dew[!(dew$Ec %in% c("FRA","MEX","PER")),]


#LRR----
colnames(dt)[colnames(dt)=="RLRSP"]="LRR"
dt$LRR=as.numeric(dt$LRR)
dt$LRR[dt$LRR>1]=NA
dt$LRR=dt$LRR*10


#LRPi:----
dt$LRP.1=NA#create LRP:
dt$LRP.2=NA
dt$LRP.3=NA
dt$LRP.4=NA
dt$LRP.5=NA
dt$LRP.6=NA

dt$LRP.1[dt$Es=="ESP_1979"]=dt$RLRPP1[dt$Es=="ESP_1979"]#assign LRP by party size order for parties with likability:
dt$LRP.2[dt$Es=="ESP_1979"]=dt$RLRPP2[dt$Es=="ESP_1979"]
dt$LRP.3[dt$Es=="ESP_1979"]=dt$RLRPP3[dt$Es=="ESP_1979"]
dt$LRP.4[dt$Es=="ESP_1979"]=dt$RLRPP4[dt$Es=="ESP_1979"]

dt$LRP.1[dt$Es=="ESP_1982"]=dt$RLRPP3[dt$Es=="ESP_1982"]
dt$LRP.2[dt$Es=="ESP_1982"]=dt$RLRPP2[dt$Es=="ESP_1982"]
dt$LRP.3[dt$Es=="ESP_1982"]=dt$RLRPP4[dt$Es=="ESP_1982"]
dt$LRP.4[dt$Es=="ESP_1982"]=dt$RLRPP1[dt$Es=="ESP_1982"]
dt$LRP.5[dt$Es=="ESP_1982"]=dt$RLRPP5[dt$Es=="ESP_1982"]

dt$LRP.1[dt$Es=="ESP_1993"]=dt$RLRPP1[dt$Es=="ESP_1993"]
dt$LRP.2[dt$Es=="ESP_1993"]=dt$RLRPP3[dt$Es=="ESP_1993"]
dt$LRP.3[dt$Es=="ESP_1993"]=dt$RLRPP4[dt$Es=="ESP_1993"]
dt$LRP.4[dt$Es=="ESP_1993"]=dt$RLRPP2[dt$Es=="ESP_1993"]

dt$LRP.1[dt$Es=="ESP_2004"]=dt$RLRPP1[dt$Es=="ESP_2004"]
dt$LRP.2[dt$Es=="ESP_2004"]=dt$RLRPP2[dt$Es=="ESP_2004"]
dt$LRP.3[dt$Es=="ESP_2004"]=dt$RLRPP3[dt$Es=="ESP_2004"]

dt$LRP.1[dt$Es=="EST_2011"]=dt$RLRPP1[dt$Es=="EST_2011"]
dt$LRP.2[dt$Es=="EST_2011"]=dt$RLRPP2[dt$Es=="EST_2011"]
dt$LRP.3[dt$Es=="EST_2011"]=dt$RLRPP3[dt$Es=="EST_2011"]
dt$LRP.4[dt$Es=="EST_2011"]=dt$RLRPP4[dt$Es=="EST_2011"]
dt$LRP.5[dt$Es=="EST_2011"]=dt$RLRPP6[dt$Es=="EST_2011"]
dt$LRP.6[dt$Es=="EST_2011"]=dt$RLRPP5[dt$Es=="EST_2011"]

dt$LRP.1[dt$Es=="FIN_2003"]=dt$RLRPP1[dt$Es=="FIN_2003"]
dt$LRP.2[dt$Es=="FIN_2003"]=dt$RLRPP3[dt$Es=="FIN_2003"]
dt$LRP.3[dt$Es=="FIN_2003"]=dt$RLRPP2[dt$Es=="FIN_2003"]
dt$LRP.4[dt$Es=="FIN_2003"]=dt$RLRPP4[dt$Es=="FIN_2003"]
dt$LRP.5[dt$Es=="FIN_2003"]=dt$RLRPP5[dt$Es=="FIN_2003"]
dt$LRP.6[dt$Es=="FIN_2003"]=dt$RLRPP6[dt$Es=="FIN_2003"]

dt$LRP.1[dt$Es=="GBR_2005"]=dt$RLRPP1[dt$Es=="GBR_2005"]
dt$LRP.2[dt$Es=="GBR_2005"]=dt$RLRPP2[dt$Es=="GBR_2005"]
dt$LRP.3[dt$Es=="GBR_2005"]=dt$RLRPP3[dt$Es=="GBR_2005"]

dt$LRP.1[dt$Es=="GRC_1985"]=dt$RLRPP1[dt$Es=="GRC_1985"]
dt$LRP.2[dt$Es=="GRC_1985"]=dt$RLRPP2[dt$Es=="GRC_1985"]
dt$LRP.3[dt$Es=="GRC_1985"]=dt$RLRPP3[dt$Es=="GRC_1985"]
dt$LRP.4[dt$Es=="GRC_1985"]=dt$RLRPP4[dt$Es=="GRC_1985"]

dt$LRP.1[dt$Es=="GRC_1989"]=dt$RLRPP1[dt$Es=="GRC_1989"]
dt$LRP.2[dt$Es=="GRC_1989"]=dt$RLRPP2[dt$Es=="GRC_1989"]
dt$LRP.3[dt$Es=="GRC_1989"]=dt$RLRPP3[dt$Es=="GRC_1989"]

dt$LRP.1[dt$Es=="GRC_1990"]=dt$RLRPP1[dt$Es=="GRC_1990"]
dt$LRP.2[dt$Es=="GRC_1990"]=dt$RLRPP2[dt$Es=="GRC_1990"]
dt$LRP.3[dt$Es=="GRC_1990"]=dt$RLRPP3[dt$Es=="GRC_1990"]

dt$LRP.1[dt$Es=="GRC_1996"]=dt$RLRPP1[dt$Es=="GRC_1996"]
dt$LRP.2[dt$Es=="GRC_1996"]=dt$RLRPP2[dt$Es=="GRC_1996"]
dt$LRP.3[dt$Es=="GRC_1996"]=dt$RLRPP3[dt$Es=="GRC_1996"]
dt$LRP.4[dt$Es=="GRC_1996"]=dt$RLRPP4[dt$Es=="GRC_1996"]
dt$LRP.5[dt$Es=="GRC_1996"]=dt$RLRPP5[dt$Es=="GRC_1996"]

dt$LRP.1[dt$Es=="GRC_2000"]=dt$RLRPP1[dt$Es=="GRC_2000"]
dt$LRP.2[dt$Es=="GRC_2000"]=dt$RLRPP2[dt$Es=="GRC_2000"]
dt$LRP.3[dt$Es=="GRC_2000"]=dt$RLRPP3[dt$Es=="GRC_2000"]
dt$LRP.4[dt$Es=="GRC_2000"]=dt$RLRPP4[dt$Es=="GRC_2000"]

dt$LRP.1[dt$Es=="GRC_2004"]=dt$RLRPP1[dt$Es=="GRC_2004"]
dt$LRP.2[dt$Es=="GRC_2004"]=dt$RLRPP2[dt$Es=="GRC_2004"]
dt$LRP.3[dt$Es=="GRC_2004"]=dt$RLRPP3[dt$Es=="GRC_2004"]
dt$LRP.4[dt$Es=="GRC_2004"]=dt$RLRPP4[dt$Es=="GRC_2004"]

dt$LRP.1[dt$Es=="GRC_2007"]=dt$RLRPP1[dt$Es=="GRC_2007"]
dt$LRP.2[dt$Es=="GRC_2007"]=dt$RLRPP2[dt$Es=="GRC_2007"]
dt$LRP.3[dt$Es=="GRC_2007"]=dt$RLRPP3[dt$Es=="GRC_2007"]
dt$LRP.4[dt$Es=="GRC_2007"]=dt$RLRPP4[dt$Es=="GRC_2007"]
dt$LRP.5[dt$Es=="GRC_2007"]=dt$RLRPP5[dt$Es=="GRC_2007"]

dt$LRP.1[dt$Es=="HUN_1998"]=dt$RLRPP1[dt$Es=="HUN_1998"]
dt$LRP.2[dt$Es=="HUN_1998"]=dt$RLRPP5[dt$Es=="HUN_1998"]
dt$LRP.3[dt$Es=="HUN_1998"]=dt$RLRPP2[dt$Es=="HUN_1998"]
dt$LRP.4[dt$Es=="HUN_1998"]=dt$RLRPP6[dt$Es=="HUN_1998"]
dt$LRP.5[dt$Es=="HUN_1998"]=dt$RLRPP4[dt$Es=="HUN_1998"]
dt$LRP.6[dt$Es=="HUN_1998"]=dt$RLRPP3[dt$Es=="HUN_1998"]

dt$LRP.1[dt$Es=="HUN_2006"]=dt$RLRPP1[dt$Es=="HUN_2006"]
dt$LRP.2[dt$Es=="HUN_2006"]=dt$RLRPP2[dt$Es=="HUN_2006"]
dt$LRP.3[dt$Es=="HUN_2006"]=dt$RLRPP3[dt$Es=="HUN_2006"]
dt$LRP.4[dt$Es=="HUN_2006"]=dt$RLRPP4[dt$Es=="HUN_2006"]

dt$LRP.1[dt$Es=="IRL_2002"]=dt$RLRPP1[dt$Es=="IRL_2002"]
dt$LRP.2[dt$Es=="IRL_2002"]=dt$RLRPP2[dt$Es=="IRL_2002"]
dt$LRP.3[dt$Es=="IRL_2002"]=dt$RLRPP4[dt$Es=="IRL_2002"]
dt$LRP.4[dt$Es=="IRL_2002"]=dt$RLRPP5[dt$Es=="IRL_2002"]
dt$LRP.5[dt$Es=="IRL_2002"]=dt$RLRPP3[dt$Es=="IRL_2002"]
dt$LRP.6[dt$Es=="IRL_2002"]=dt$RLRPP6[dt$Es=="IRL_2002"]

dt$LRP.1[dt$Es=="ISL_1987"]=dt$RLRPP3[dt$Es=="ISL_1987"]
dt$LRP.2[dt$Es=="ISL_1987"]=dt$RLRPP2[dt$Es=="ISL_1987"]
dt$LRP.3[dt$Es=="ISL_1987"]=dt$RLRPP1[dt$Es=="ISL_1987"]
dt$LRP.4[dt$Es=="ISL_1987"]=dt$RLRPP4[dt$Es=="ISL_1987"]
dt$LRP.5[dt$Es=="ISL_1987"]=dt$RLRPP5[dt$Es=="ISL_1987"]

dt$LRP.1[dt$Es=="ISL_1991"]=dt$RLRPP3[dt$Es=="ISL_1991"]
dt$LRP.2[dt$Es=="ISL_1991"]=dt$RLRPP2[dt$Es=="ISL_1991"]
dt$LRP.3[dt$Es=="ISL_1991"]=dt$RLRPP1[dt$Es=="ISL_1991"]
dt$LRP.4[dt$Es=="ISL_1991"]=dt$RLRPP4[dt$Es=="ISL_1991"]
dt$LRP.5[dt$Es=="ISL_1991"]=dt$RLRPP5[dt$Es=="ISL_1991"]

dt$LRP.1[dt$Es=="ISL_1995"]=dt$RLRPP3[dt$Es=="ISL_1995"]
dt$LRP.2[dt$Es=="ISL_1995"]=dt$RLRPP2[dt$Es=="ISL_1995"]
dt$LRP.3[dt$Es=="ISL_1995"]=dt$RLRPP4[dt$Es=="ISL_1995"]
dt$LRP.4[dt$Es=="ISL_1995"]=dt$RLRPP1[dt$Es=="ISL_1995"]
dt$LRP.5[dt$Es=="ISL_1995"]=dt$RLRPP5[dt$Es=="ISL_1995"]
dt$LRP.6[dt$Es=="ISL_1995"]=dt$RLRPP6[dt$Es=="ISL_1995"]

dt$LRP.1[dt$Es=="ISL_2003"]=dt$RLRPP3[dt$Es=="ISL_2003"]
dt$LRP.2[dt$Es=="ISL_2003"]=dt$RLRPP1[dt$Es=="ISL_2003"]
dt$LRP.3[dt$Es=="ISL_2003"]=dt$RLRPP2[dt$Es=="ISL_2003"]
dt$LRP.4[dt$Es=="ISL_2003"]=dt$RLRPP4[dt$Es=="ISL_2003"]
dt$LRP.5[dt$Es=="ISL_2003"]=dt$RLRPP5[dt$Es=="ISL_2003"]

dt$LRP.1[dt$Es=="ITA_2006"]=dt$RLRPP3[dt$Es=="ITA_2006"]#coalition==1
dt$LRP.2[dt$Es=="ITA_2006"]=dt$RLRPP5[dt$Es=="ITA_2006"]
dt$LRP.3[dt$Es=="ITA_2006"]=dt$RLRPP6[dt$Es=="ITA_2006"]
dt$LRP.4[dt$Es=="ITA_2006"]=dt$RLRPP4[dt$Es=="ITA_2006"]
dt$LRP.5[dt$Es=="ITA_2006"]=dt$RLRPP1[dt$Es=="ITA_2006"]
dt$LRP.6[dt$Es=="ITA_2006"]=dt$RLRPP7[dt$Es=="ITA_2006"]

dt$LRP.1[dt$Es=="ITA_2008"]=dt$RLRPP4[dt$Es=="ITA_2008"]#coalition==1
dt$LRP.2[dt$Es=="ITA_2008"]=dt$RLRPP2[dt$Es=="ITA_2008"]
dt$LRP.3[dt$Es=="ITA_2008"]=dt$RLRPP5[dt$Es=="ITA_2008"]
dt$LRP.4[dt$Es=="ITA_2008"]=dt$RLRPP6[dt$Es=="ITA_2008"]
dt$LRP.5[dt$Es=="ITA_2008"]=dt$RLRPP3[dt$Es=="ITA_2008"]
dt$LRP.6[dt$Es=="ITA_2008"]=dt$RLRPP1[dt$Es=="ITA_2008"]

dt$LRP.1[dt$Es=="LTU_2000"]=dt$RLRPP2[dt$Es=="LTU_2000"]
dt$LRP.2[dt$Es=="LTU_2000"]=dt$RLRPP3[dt$Es=="LTU_2000"]
dt$LRP.3[dt$Es=="LTU_2000"]=dt$RLRPP4[dt$Es=="LTU_2000"]
dt$LRP.4[dt$Es=="LTU_2000"]=dt$RLRPP1[dt$Es=="LTU_2000"]

dt$LRP.1[dt$Es=="NLD_2002"]=dt$RLRPP2[dt$Es=="NLD_2002"]
dt$LRP.2[dt$Es=="NLD_2002"]=dt$RLRPP6[dt$Es=="NLD_2002"]
dt$LRP.3[dt$Es=="NLD_2002"]=dt$RLRPP3[dt$Es=="NLD_2002"]
dt$LRP.4[dt$Es=="NLD_2002"]=dt$RLRPP1[dt$Es=="NLD_2002"]
dt$LRP.5[dt$Es=="NLD_2002"]=dt$RLRPP5[dt$Es=="NLD_2002"]
dt$LRP.6[dt$Es=="NLD_2002"]=dt$RLRPP7[dt$Es=="NLD_2002"]

dt$LRP.1[dt$Es=="NOR_2001"]=dt$RLRPP2[dt$Es=="NOR_2001"]
dt$LRP.2[dt$Es=="NOR_2001"]=dt$RLRPP6[dt$Es=="NOR_2001"]
dt$LRP.3[dt$Es=="NOR_2001"]=dt$RLRPP7[dt$Es=="NOR_2001"]
dt$LRP.4[dt$Es=="NOR_2001"]=dt$RLRPP1[dt$Es=="NOR_2001"]
dt$LRP.5[dt$Es=="NOR_2001"]=dt$RLRPP4[dt$Es=="NOR_2001"]
dt$LRP.6[dt$Es=="NOR_2001"]=dt$RLRPP5[dt$Es=="NOR_2001"]

dt$LRP.1[dt$Es=="PRT_2005"]=dt$RLRPP5[dt$Es=="PRT_2005"]
dt$LRP.2[dt$Es=="PRT_2005"]=dt$RLRPP4[dt$Es=="PRT_2005"]
dt$LRP.3[dt$Es=="PRT_2005"]=dt$RLRPP3[dt$Es=="PRT_2005"]
dt$LRP.4[dt$Es=="PRT_2005"]=dt$RLRPP2[dt$Es=="PRT_2005"]
dt$LRP.5[dt$Es=="PRT_2005"]=dt$RLRPP1[dt$Es=="PRT_2005"]

dt$LRP.1[dt$Es=="SVN_2000"]=dt$RLRPP2[dt$Es=="SVN_2000"]
dt$LRP.2[dt$Es=="SVN_2000"]=dt$RLRPP5[dt$Es=="SVN_2000"]
dt$LRP.3[dt$Es=="SVN_2000"]=dt$RLRPP7[dt$Es=="SVN_2000"]
dt$LRP.4[dt$Es=="SVN_2000"]=dt$RLRPP3[dt$Es=="SVN_2000"]
dt$LRP.5[dt$Es=="SVN_2000"]=dt$RLRPP6[dt$Es=="SVN_2000"]
dt$LRP.6[dt$Es=="SVN_2000"]=dt$RLRPP1[dt$Es=="SVN_2000"]

dt$LRP.1[dt$Es=="SWE_1979"]=dt$RLRPP2[dt$Es=="SWE_1979"]
dt$LRP.2[dt$Es=="SWE_1979"]=dt$RLRPP5[dt$Es=="SWE_1979"]
dt$LRP.3[dt$Es=="SWE_1979"]=dt$RLRPP3[dt$Es=="SWE_1979"]
dt$LRP.4[dt$Es=="SWE_1979"]=dt$RLRPP4[dt$Es=="SWE_1979"]
dt$LRP.5[dt$Es=="SWE_1979"]=dt$RLRPP1[dt$Es=="SWE_1979"]

dt$LRP.1[dt$Es=="SWE_2002"]=dt$RLRPP2[dt$Es=="SWE_2002"]
dt$LRP.2[dt$Es=="SWE_2002"]=dt$RLRPP5[dt$Es=="SWE_2002"]
dt$LRP.3[dt$Es=="SWE_2002"]=dt$RLRPP4[dt$Es=="SWE_2002"]
dt$LRP.4[dt$Es=="SWE_2002"]=dt$RLRPP6[dt$Es=="SWE_2002"]
dt$LRP.5[dt$Es=="SWE_2002"]=dt$RLRPP1[dt$Es=="SWE_2002"]
dt$LRP.6[dt$Es=="SWE_2002"]=dt$RLRPP3[dt$Es=="SWE_2002"]

dt$LRP.1[dt$Es=="SWE_2010"]=dt$RLRPP2[dt$Es=="SWE_2010"]
dt$LRP.2[dt$Es=="SWE_2010"]=dt$RLRPP5[dt$Es=="SWE_2010"]
dt$LRP.3[dt$Es=="SWE_2010"]=dt$RLRPP7[dt$Es=="SWE_2010"]
dt$LRP.4[dt$Es=="SWE_2010"]=dt$RLRPP4[dt$Es=="SWE_2010"]
dt$LRP.5[dt$Es=="SWE_2010"]=dt$RLRPP3[dt$Es=="SWE_2010"]
dt$LRP.6[dt$Es=="SWE_2010"]=dt$RLRPP10[dt$Es=="SWE_2010"]

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$LRP.1[dt$Es=="DEU_1961"]=dt$RLRPP2[dt$Es=="DEU_1961"]
dt$LRP.2[dt$Es=="DEU_1961"]=dt$RLRPP1[dt$Es=="DEU_1961"]
dt$LRP.3[dt$Es=="DEU_1961"]=dt$RLRPP3[dt$Es=="DEU_1961"]

dt$LRP.1[dt$Es=="DEU_1965"]=dt$RLRPP2[dt$Es=="DEU_1965"]
dt$LRP.2[dt$Es=="DEU_1965"]=dt$RLRPP1[dt$Es=="DEU_1965"]
dt$LRP.3[dt$Es=="DEU_1965"]=dt$RLRPP3[dt$Es=="DEU_1965"]

dt$LRP.1[dt$Es=="DEU_1976"]=dt$RLRPP2[dt$Es=="DEU_1976"]
dt$LRP.2[dt$Es=="DEU_1976"]=dt$RLRPP1[dt$Es=="DEU_1976"]
dt$LRP.3[dt$Es=="DEU_1976"]=dt$RLRPP3[dt$Es=="DEU_1976"]

dt$LRP.1[dt$Es=="DEU_1980"]=dt$RLRPP2[dt$Es=="DEU_1980"]
dt$LRP.2[dt$Es=="DEU_1980"]=dt$RLRPP1[dt$Es=="DEU_1980"]
dt$LRP.3[dt$Es=="DEU_1980"]=dt$RLRPP3[dt$Es=="DEU_1980"]

dt$LRP.1[dt$Es=="DEU_1983"]=dt$RLRPP2[dt$Es=="DEU_1983"]
dt$LRP.2[dt$Es=="DEU_1983"]=dt$RLRPP1[dt$Es=="DEU_1983"]
dt$LRP.3[dt$Es=="DEU_1983"]=dt$RLRPP3[dt$Es=="DEU_1983"]

dt$LRP.1[dt$Es=="DEU_1987"]=dt$RLRPP2[dt$Es=="DEU_1987"]
dt$LRP.2[dt$Es=="DEU_1987"]=dt$RLRPP1[dt$Es=="DEU_1987"]
dt$LRP.3[dt$Es=="DEU_1987"]=dt$RLRPP3[dt$Es=="DEU_1987"]

dt$LRP.1[dt$Es=="DEU_1990"]=dt$RLRPP2[dt$Es=="DEU_1990"]
dt$LRP.2[dt$Es=="DEU_1990"]=dt$RLRPP1[dt$Es=="DEU_1990"]
dt$LRP.3[dt$Es=="DEU_1990"]=dt$RLRPP3[dt$Es=="DEU_1990"]
dt$LRP.4[dt$Es=="DEU_1990"]=dt$RLRPP5[dt$Es=="DEU_1990"]

dt$LRP.1[dt$Es=="DEU_1994"]=dt$RLRPP2[dt$Es=="DEU_1994"]
dt$LRP.2[dt$Es=="DEU_1994"]=dt$RLRPP1[dt$Es=="DEU_1994"]
dt$LRP.3[dt$Es=="DEU_1994"]=dt$RLRPP4[dt$Es=="DEU_1994"]
dt$LRP.4[dt$Es=="DEU_1994"]=dt$RLRPP3[dt$Es=="DEU_1994"]
dt$LRP.5[dt$Es=="DEU_1994"]=dt$RLRPP5[dt$Es=="DEU_1994"]

dt$LRP.1[dt$Es=="DEU_1998"]=dt$RLRPP1[dt$Es=="DEU_1998"]
dt$LRP.2[dt$Es=="DEU_1998"]=dt$RLRPP2[dt$Es=="DEU_1998"]
dt$LRP.3[dt$Es=="DEU_1998"]=dt$RLRPP4[dt$Es=="DEU_1998"]
dt$LRP.4[dt$Es=="DEU_1998"]=dt$RLRPP3[dt$Es=="DEU_1998"]
dt$LRP.5[dt$Es=="DEU_1998"]=dt$RLRPP5[dt$Es=="DEU_1998"]

dt$LRP.1[dt$Es=="DEU_2009"]=dt$RLRPP2[dt$Es=="DEU_2009"]
dt$LRP.2[dt$Es=="DEU_2009"]=dt$RLRPP1[dt$Es=="DEU_2009"]
dt$LRP.3[dt$Es=="DEU_2009"]=dt$RLRPP3[dt$Es=="DEU_2009"]
dt$LRP.4[dt$Es=="DEU_2009"]=dt$RLRPP5[dt$Es=="DEU_2009"]
dt$LRP.5[dt$Es=="DEU_2009"]=dt$RLRPP4[dt$Es=="DEU_2009"]

dt$LRP.1[dt$Es=="DEU_2013"]=dt$RLRPP2[dt$Es=="DEU_2013"]
dt$LRP.2[dt$Es=="DEU_2013"]=dt$RLRPP1[dt$Es=="DEU_2013"]
dt$LRP.3[dt$Es=="DEU_2013"]=dt$RLRPP5[dt$Es=="DEU_2013"]
dt$LRP.4[dt$Es=="DEU_2013"]=dt$RLRPP4[dt$Es=="DEU_2013"]
dt$LRP.5[dt$Es=="DEU_2013"]=dt$RLRPP3[dt$Es=="DEU_2013"]

dt$LRP.1[dt$Es=="FIN_2007"]=dt$RLRPP1[dt$Es=="FIN_2007"]
dt$LRP.2[dt$Es=="FIN_2007"]=dt$RLRPP3[dt$Es=="FIN_2007"]
dt$LRP.3[dt$Es=="FIN_2007"]=dt$RLRPP2[dt$Es=="FIN_2007"]
dt$LRP.4[dt$Es=="FIN_2007"]=dt$RLRPP4[dt$Es=="FIN_2007"]
dt$LRP.5[dt$Es=="FIN_2007"]=dt$RLRPP5[dt$Es=="FIN_2007"]
dt$LRP.6[dt$Es=="FIN_2007"]=dt$RLRPP7[dt$Es=="FIN_2007"]

dt$LRP.1[dt$Es=="FIN_2011"]=dt$RLRPP3[dt$Es=="FIN_2011"]
dt$LRP.2[dt$Es=="FIN_2011"]=dt$RLRPP2[dt$Es=="FIN_2011"]
dt$LRP.3[dt$Es=="FIN_2011"]=dt$RLRPP8[dt$Es=="FIN_2011"]
dt$LRP.4[dt$Es=="FIN_2011"]=dt$RLRPP1[dt$Es=="FIN_2011"]
dt$LRP.5[dt$Es=="FIN_2011"]=dt$RLRPP4[dt$Es=="FIN_2011"]
dt$LRP.6[dt$Es=="FIN_2011"]=dt$RLRPP5[dt$Es=="FIN_2011"]

dt$LRP.1[dt$Es=="GRC_2009"]=dt$RLRPP1[dt$Es=="GRC_2009"]
dt$LRP.2[dt$Es=="GRC_2009"]=dt$RLRPP2[dt$Es=="GRC_2009"]
dt$LRP.3[dt$Es=="GRC_2009"]=dt$RLRPP3[dt$Es=="GRC_2009"]
dt$LRP.4[dt$Es=="GRC_2009"]=dt$RLRPP4[dt$Es=="GRC_2009"]
dt$LRP.5[dt$Es=="GRC_2009"]=dt$RLRPP5[dt$Es=="GRC_2009"]
dt$LRP.6[dt$Es=="GRC_2009"]=dt$RLRPP6[dt$Es=="GRC_2009"]

dt$LRP.1[dt$Es=="GRC_2012"]=dt$RLRPP1[dt$Es=="GRC_2012"]
dt$LRP.2[dt$Es=="GRC_2012"]=dt$RLRPP2[dt$Es=="GRC_2012"]
dt$LRP.3[dt$Es=="GRC_2012"]=dt$RLRPP3[dt$Es=="GRC_2012"]
dt$LRP.4[dt$Es=="GRC_2012"]=dt$RLRPP4[dt$Es=="GRC_2012"]
dt$LRP.5[dt$Es=="GRC_2012"]=dt$RLRPP5[dt$Es=="GRC_2012"]
dt$LRP.6[dt$Es=="GRC_2012"]=dt$RLRPP6[dt$Es=="GRC_2012"]

dt$LRP.1[dt$Es=="IRL_2007"]=dt$RLRPP1[dt$Es=="IRL_2007"]
dt$LRP.2[dt$Es=="IRL_2007"]=dt$RLRPP2[dt$Es=="IRL_2007"]
dt$LRP.3[dt$Es=="IRL_2007"]=dt$RLRPP4[dt$Es=="IRL_2007"]
dt$LRP.4[dt$Es=="IRL_2007"]=dt$RLRPP3[dt$Es=="IRL_2007"]
dt$LRP.5[dt$Es=="IRL_2007"]=dt$RLRPP6[dt$Es=="IRL_2007"]
dt$LRP.6[dt$Es=="IRL_2007"]=dt$RLRPP5[dt$Es=="IRL_2007"]

dt$LRP.1[dt$Es=="IRL_2011"]=dt$RLRPP2[dt$Es=="IRL_2011"]
dt$LRP.2[dt$Es=="IRL_2011"]=dt$RLRPP3[dt$Es=="IRL_2011"]
dt$LRP.3[dt$Es=="IRL_2011"]=dt$RLRPP1[dt$Es=="IRL_2011"]
dt$LRP.4[dt$Es=="IRL_2011"]=dt$RLRPP4[dt$Es=="IRL_2011"]
dt$LRP.5[dt$Es=="IRL_2011"]=dt$RLRPP5[dt$Es=="IRL_2011"]#

dt$LRP.1[dt$Es=="ISL_1999"]=dt$RLRPP3[dt$Es=="ISL_1999"]
dt$LRP.2[dt$Es=="ISL_1999"]=dt$RLRPP1[dt$Es=="ISL_1999"]
dt$LRP.3[dt$Es=="ISL_1999"]=dt$RLRPP2[dt$Es=="ISL_1999"]
dt$LRP.4[dt$Es=="ISL_1999"]=dt$RLRPP4[dt$Es=="ISL_1999"]
dt$LRP.5[dt$Es=="ISL_1999"]=dt$RLRPP5[dt$Es=="ISL_1999"]

dt$LRP.1[dt$Es=="ISL_2007"]=dt$RLRPP3[dt$Es=="ISL_2007"]
dt$LRP.2[dt$Es=="ISL_2007"]=dt$RLRPP1[dt$Es=="ISL_2007"]
dt$LRP.3[dt$Es=="ISL_2007"]=dt$RLRPP4[dt$Es=="ISL_2007"]
dt$LRP.4[dt$Es=="ISL_2007"]=dt$RLRPP2[dt$Es=="ISL_2007"]
dt$LRP.5[dt$Es=="ISL_2007"]=dt$RLRPP5[dt$Es=="ISL_2007"]
dt$LRP.6[dt$Es=="ISL_2007"]=dt$RLRPP6[dt$Es=="ISL_2007"]#

dt$LRP.1[dt$Es=="ISL_2009"]=dt$RLRPP1[dt$Es=="ISL_2009"]
dt$LRP.2[dt$Es=="ISL_2009"]=dt$RLRPP3[dt$Es=="ISL_2009"]
dt$LRP.3[dt$Es=="ISL_2009"]=dt$RLRPP4[dt$Es=="ISL_2009"]
dt$LRP.4[dt$Es=="ISL_2009"]=dt$RLRPP2[dt$Es=="ISL_2009"]
dt$LRP.5[dt$Es=="ISL_2009"]=dt$RLRPP5[dt$Es=="ISL_2009"]#
dt$LRP.6[dt$Es=="ISL_2009"]=dt$RLRPP6[dt$Es=="ISL_2009"]#

dt$LRP.1[dt$Es=="ISL_2013"]=dt$RLRPP3[dt$Es=="ISL_2013"]
dt$LRP.2[dt$Es=="ISL_2013"]=dt$RLRPP2[dt$Es=="ISL_2013"]
dt$LRP.3[dt$Es=="ISL_2013"]=dt$RLRPP1[dt$Es=="ISL_2013"]
dt$LRP.4[dt$Es=="ISL_2013"]=dt$RLRPP4[dt$Es=="ISL_2013"]
dt$LRP.5[dt$Es=="ISL_2013"]=dt$RLRPP5[dt$Es=="ISL_2013"]
dt$LRP.6[dt$Es=="ISL_2013"]=dt$RLRPP6[dt$Es=="ISL_2013"]

dt$LRP.1[dt$Es=="NLD_1994"]=dt$RLRPP1[dt$Es=="NLD_1994"]
dt$LRP.2[dt$Es=="NLD_1994"]=dt$RLRPP2[dt$Es=="NLD_1994"]
dt$LRP.3[dt$Es=="NLD_1994"]=dt$RLRPP3[dt$Es=="NLD_1994"]
dt$LRP.4[dt$Es=="NLD_1994"]=dt$RLRPP4[dt$Es=="NLD_1994"]

dt$LRP.1[dt$Es=="NLD_1998"]=dt$RLRPP1[dt$Es=="NLD_1998"]#EV 4 parties, CSES 6 parties coded
dt$LRP.2[dt$Es=="NLD_1998"]=dt$RLRPP3[dt$Es=="NLD_1998"]
dt$LRP.3[dt$Es=="NLD_1998"]=dt$RLRPP2[dt$Es=="NLD_1998"]
dt$LRP.4[dt$Es=="NLD_1998"]=dt$RLRPP4[dt$Es=="NLD_1998"]
dt$LRP.5[dt$Es=="NLD_1998"]=dt$RLRPP5[dt$Es=="NLD_1998"]
dt$LRP.6[dt$Es=="NLD_1998"]=dt$RLRPP7[dt$Es=="NLD_1998"]#

dt$LRP.1[dt$Es=="NOR_1981"]=dt$RLRPP2[dt$Es=="NOR_1981"]
dt$LRP.2[dt$Es=="NOR_1981"]=dt$RLRPP6[dt$Es=="NOR_1981"]
dt$LRP.3[dt$Es=="NOR_1981"]=dt$RLRPP4[dt$Es=="NOR_1981"]
dt$LRP.4[dt$Es=="NOR_1981"]=dt$RLRPP5[dt$Es=="NOR_1981"]
dt$LRP.5[dt$Es=="NOR_1981"]=dt$RLRPP1[dt$Es=="NOR_1981"]
dt$LRP.6[dt$Es=="NOR_1981"]=dt$RLRPP7[dt$Es=="NOR_1981"]

dt$LRP.1[dt$Es=="NOR_1985"]=dt$RLRPP2[dt$Es=="NOR_1985"]
dt$LRP.2[dt$Es=="NOR_1985"]=dt$RLRPP6[dt$Es=="NOR_1985"]
dt$LRP.3[dt$Es=="NOR_1985"]=dt$RLRPP4[dt$Es=="NOR_1985"]
dt$LRP.4[dt$Es=="NOR_1985"]=dt$RLRPP5[dt$Es=="NOR_1985"]
dt$LRP.5[dt$Es=="NOR_1985"]=dt$RLRPP1[dt$Es=="NOR_1985"]
dt$LRP.6[dt$Es=="NOR_1985"]=dt$RLRPP7[dt$Es=="NOR_1985"]

dt$LRP.1[dt$Es=="NOR_1989"]=dt$RLRPP2[dt$Es=="NOR_1989"]
dt$LRP.2[dt$Es=="NOR_1989"]=dt$RLRPP6[dt$Es=="NOR_1989"]
dt$LRP.3[dt$Es=="NOR_1989"]=dt$RLRPP7[dt$Es=="NOR_1989"]
dt$LRP.4[dt$Es=="NOR_1989"]=dt$RLRPP1[dt$Es=="NOR_1989"]
dt$LRP.5[dt$Es=="NOR_1989"]=dt$RLRPP4[dt$Es=="NOR_1989"]
dt$LRP.6[dt$Es=="NOR_1989"]=dt$RLRPP5[dt$Es=="NOR_1989"]

dt$LRP.1[dt$Es=="NOR_1993"]=dt$RLRPP2[dt$Es=="NOR_1993"]
dt$LRP.2[dt$Es=="NOR_1993"]=dt$RLRPP5[dt$Es=="NOR_1993"]
dt$LRP.3[dt$Es=="NOR_1993"]=dt$RLRPP6[dt$Es=="NOR_1993"]
dt$LRP.4[dt$Es=="NOR_1993"]=dt$RLRPP1[dt$Es=="NOR_1993"]
dt$LRP.5[dt$Es=="NOR_1993"]=dt$RLRPP4[dt$Es=="NOR_1993"]
dt$LRP.6[dt$Es=="NOR_1993"]=dt$RLRPP7[dt$Es=="NOR_1993"]

dt$LRP.1[dt$Es=="NOR_1997"]=dt$RLRPP2[dt$Es=="NOR_1997"]
dt$LRP.2[dt$Es=="NOR_1997"]=dt$RLRPP7[dt$Es=="NOR_1997"]
dt$LRP.3[dt$Es=="NOR_1997"]=dt$RLRPP4[dt$Es=="NOR_1997"]
dt$LRP.4[dt$Es=="NOR_1997"]=dt$RLRPP6[dt$Es=="NOR_1997"]
dt$LRP.5[dt$Es=="NOR_1997"]=dt$RLRPP5[dt$Es=="NOR_1997"]
dt$LRP.6[dt$Es=="NOR_1997"]=dt$RLRPP1[dt$Es=="NOR_1997"]

dt$LRP.1[dt$Es=="NOR_2005"]=dt$RLRPP2[dt$Es=="NOR_2005"]
dt$LRP.2[dt$Es=="NOR_2005"]=dt$RLRPP7[dt$Es=="NOR_2005"]
dt$LRP.3[dt$Es=="NOR_2005"]=dt$RLRPP6[dt$Es=="NOR_2005"]
dt$LRP.4[dt$Es=="NOR_2005"]=dt$RLRPP1[dt$Es=="NOR_2005"]
dt$LRP.5[dt$Es=="NOR_2005"]=dt$RLRPP4[dt$Es=="NOR_2005"]
dt$LRP.6[dt$Es=="NOR_2005"]=dt$RLRPP5[dt$Es=="NOR_2005"]

dt$LRP.1[dt$Es=="PRT_2002"]=dt$RLRPP4[dt$Es=="PRT_2002"]
dt$LRP.2[dt$Es=="PRT_2002"]=dt$RLRPP5[dt$Es=="PRT_2002"]
dt$LRP.3[dt$Es=="PRT_2002"]=dt$RLRPP2[dt$Es=="PRT_2002"]
dt$LRP.4[dt$Es=="PRT_2002"]=dt$RLRPP3[dt$Es=="PRT_2002"]
dt$LRP.5[dt$Es=="PRT_2002"]=dt$RLRPP1[dt$Es=="PRT_2002"]
dt$LRP.6[dt$Es=="PRT_2002"]=dt$RLRPP6[dt$Es=="PRT_2002"]

dt$LRP.1[dt$Es=="PRT_2009"]=dt$RLRPP5[dt$Es=="PRT_2009"]#osym4-5  inverted!?
dt$LRP.2[dt$Es=="PRT_2009"]=dt$RLRPP4[dt$Es=="PRT_2009"]
dt$LRP.3[dt$Es=="PRT_2009"]=dt$RLRPP2[dt$Es=="PRT_2009"]
dt$LRP.4[dt$Es=="PRT_2009"]=dt$RLRPP1[dt$Es=="PRT_2009"]
dt$LRP.5[dt$Es=="PRT_2009"]=dt$RLRPP3[dt$Es=="PRT_2009"]

dt$LRP.1[dt$Es=="SWE_1982"]=dt$RLRPP2[dt$Es=="SWE_1982"]
dt$LRP.2[dt$Es=="SWE_1982"]=dt$RLRPP5[dt$Es=="SWE_1982"]
dt$LRP.3[dt$Es=="SWE_1982"]=dt$RLRPP3[dt$Es=="SWE_1982"]
dt$LRP.4[dt$Es=="SWE_1982"]=dt$RLRPP4[dt$Es=="SWE_1982"]
dt$LRP.5[dt$Es=="SWE_1982"]=dt$RLRPP1[dt$Es=="SWE_1982"]

dt$LRP.1[dt$Es=="SWE_1985"]=dt$RLRPP2[dt$Es=="SWE_1985"]
dt$LRP.2[dt$Es=="SWE_1985"]=dt$RLRPP5[dt$Es=="SWE_1985"]
dt$LRP.3[dt$Es=="SWE_1985"]=dt$RLRPP4[dt$Es=="SWE_1985"]
dt$LRP.4[dt$Es=="SWE_1985"]=dt$RLRPP3[dt$Es=="SWE_1985"]
dt$LRP.5[dt$Es=="SWE_1985"]=dt$RLRPP1[dt$Es=="SWE_1985"]
dt$LRP.6[dt$Es=="SWE_1985"]=dt$RLRPP6[dt$Es=="SWE_1985"]

dt$LRP.1[dt$Es=="SWE_1988"]=dt$RLRPP2[dt$Es=="SWE_1988"]
dt$LRP.2[dt$Es=="SWE_1988"]=dt$RLRPP5[dt$Es=="SWE_1988"]
dt$LRP.3[dt$Es=="SWE_1988"]=dt$RLRPP4[dt$Es=="SWE_1988"]
dt$LRP.4[dt$Es=="SWE_1988"]=dt$RLRPP3[dt$Es=="SWE_1988"]
dt$LRP.5[dt$Es=="SWE_1988"]=dt$RLRPP1[dt$Es=="SWE_1988"]

dt$LRP.1[dt$Es=="SWE_1991"]=dt$RLRPP2[dt$Es=="SWE_1991"]
dt$LRP.2[dt$Es=="SWE_1991"]=dt$RLRPP5[dt$Es=="SWE_1991"]
dt$LRP.3[dt$Es=="SWE_1991"]=dt$RLRPP4[dt$Es=="SWE_1991"]
dt$LRP.4[dt$Es=="SWE_1991"]=dt$RLRPP3[dt$Es=="SWE_1991"]
dt$LRP.5[dt$Es=="SWE_1991"]=dt$RLRPP6[dt$Es=="SWE_1991"]
dt$LRP.6[dt$Es=="SWE_1991"]=dt$RLRPP9[dt$Es=="SWE_1991"]

dt$LRP.1[dt$Es=="SWE_1994"]=dt$RLRPP2[dt$Es=="SWE_1994"]
dt$LRP.2[dt$Es=="SWE_1994"]=dt$RLRPP5[dt$Es=="SWE_1994"]
dt$LRP.3[dt$Es=="SWE_1994"]=dt$RLRPP3[dt$Es=="SWE_1994"]
dt$LRP.4[dt$Es=="SWE_1994"]=dt$RLRPP4[dt$Es=="SWE_1994"]
dt$LRP.5[dt$Es=="SWE_1994"]=dt$RLRPP1[dt$Es=="SWE_1994"]
dt$LRP.6[dt$Es=="SWE_1994"]=dt$RLRPP7[dt$Es=="SWE_1994"]

dt$LRP.1[dt$Es=="SWE_1998"]=dt$RLRPP2[dt$Es=="SWE_1998"]
dt$LRP.2[dt$Es=="SWE_1998"]=dt$RLRPP5[dt$Es=="SWE_1998"]
dt$LRP.3[dt$Es=="SWE_1998"]=dt$RLRPP1[dt$Es=="SWE_1998"]
dt$LRP.4[dt$Es=="SWE_1998"]=dt$RLRPP6[dt$Es=="SWE_1998"]
dt$LRP.5[dt$Es=="SWE_1998"]=dt$RLRPP3[dt$Es=="SWE_1998"]
dt$LRP.6[dt$Es=="SWE_1998"]=dt$RLRPP4[dt$Es=="SWE_1998"]

dt$LRP.1[dt$Es=="SWE_2006"]=dt$RLRPP2[dt$Es=="SWE_2006"]
dt$LRP.2[dt$Es=="SWE_2006"]=dt$RLRPP5[dt$Es=="SWE_2006"]
dt$LRP.3[dt$Es=="SWE_2006"]=dt$RLRPP3[dt$Es=="SWE_2006"]
dt$LRP.4[dt$Es=="SWE_2006"]=dt$RLRPP4[dt$Es=="SWE_2006"]
dt$LRP.5[dt$Es=="SWE_2006"]=dt$RLRPP6[dt$Es=="SWE_2006"]
dt$LRP.6[dt$Es=="SWE_2006"]=dt$RLRPP1[dt$Es=="SWE_2006"]

dt$LRP.1=as.numeric(dt$LRP.1)#recode as numeric:
dt$LRP.2=as.numeric(dt$LRP.2)
dt$LRP.3=as.numeric(dt$LRP.3)
dt$LRP.4=as.numeric(dt$LRP.4)
dt$LRP.5=as.numeric(dt$LRP.5)
dt$LRP.6=as.numeric(dt$LRP.6)

dt$LRP.1[dt$LRP.1>1]=NA#exclude NAs coded 900s:
dt$LRP.2[dt$LRP.2>1]=NA
dt$LRP.3[dt$LRP.3>1]=NA
dt$LRP.4[dt$LRP.4>1]=NA
dt$LRP.5[dt$LRP.5>1]=NA
dt$LRP.6[dt$LRP.6>1]=NA

dt$LRP.1=dt$LRP.1*10#recode to 0-10 scale:
dt$LRP.2=dt$LRP.2*10
dt$LRP.3=dt$LRP.3*10
dt$LRP.4=dt$LRP.4*10
dt$LRP.5=dt$LRP.5*10
dt$LRP.6=dt$LRP.6*10


#NP:----
dt$NP=NA
dt$NP[dt$Es=="ESP_1979"]=4
dt$NP[dt$Es=="ESP_1982"]=5
dt$NP[dt$Es=="ESP_1993"]=4
dt$NP[dt$Es=="ESP_2004"]=3
dt$NP[dt$Es=="EST_2011"]=6
dt$NP[dt$Es=="FIN_2003"]=6
dt$NP[dt$Es=="GBR_2005"]=3
dt$NP[dt$Es=="GRC_1985"]=4
dt$NP[dt$Es=="GRC_1989"]=3
dt$NP[dt$Es=="GRC_1990"]=3
dt$NP[dt$Es=="GRC_1996"]=5
dt$NP[dt$Es=="GRC_2000"]=4
dt$NP[dt$Es=="GRC_2004"]=4
dt$NP[dt$Es=="GRC_2007"]=5
dt$NP[dt$Es=="HUN_1998"]=6
dt$NP[dt$Es=="HUN_2006"]=4
dt$NP[dt$Es=="IRL_2002"]=6
dt$NP[dt$Es=="ISL_1987"]=5
dt$NP[dt$Es=="ISL_1991"]=5
dt$NP[dt$Es=="ISL_1995"]=6
dt$NP[dt$Es=="ISL_2003"]=5
dt$NP[dt$Es=="ITA_2006"]=6
dt$NP[dt$Es=="ITA_2008"]=6
dt$NP[dt$Es=="LTU_2000"]=4
dt$NP[dt$Es=="NLD_2002"]=6
dt$NP[dt$Es=="NOR_2001"]=6
dt$NP[dt$Es=="PRT_2005"]=5
dt$NP[dt$Es=="SVN_2000"]=6
dt$NP[dt$Es=="SWE_1979"]=5
dt$NP[dt$Es=="SWE_2002"]=6
dt$NP[dt$Es=="SWE_2010"]=6

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$NP[dt$Es=="DEU_1961"]=3
dt$NP[dt$Es=="DEU_1965"]=3
dt$NP[dt$Es=="DEU_1976"]=3
dt$NP[dt$Es=="DEU_1980"]=3
dt$NP[dt$Es=="DEU_1983"]=3
dt$NP[dt$Es=="DEU_1987"]=3
dt$NP[dt$Es=="DEU_1990"]=4
dt$NP[dt$Es=="DEU_1994"]=5
dt$NP[dt$Es=="DEU_1998"]=5
dt$NP[dt$Es=="DEU_2009"]=5
dt$NP[dt$Es=="DEU_2013"]=5
dt$NP[dt$Es=="FIN_2007"]=6
dt$NP[dt$Es=="FIN_2011"]=6
dt$NP[dt$Es=="GRC_2009"]=6
dt$NP[dt$Es=="GRC_2012"]=6
dt$NP[dt$Es=="IRL_2007"]=6
dt$NP[dt$Es=="IRL_2011"]=5
dt$NP[dt$Es=="ISL_1999"]=5
dt$NP[dt$Es=="ISL_2007"]=6
dt$NP[dt$Es=="ISL_2009"]=6
dt$NP[dt$Es=="ISL_2013"]=6
dt$NP[dt$Es=="NLD_1994"]=4
dt$NP[dt$Es=="NLD_1998"]=6
dt$NP[dt$Es=="NOR_1981"]=6
dt$NP[dt$Es=="NOR_1985"]=6
dt$NP[dt$Es=="NOR_1989"]=6
dt$NP[dt$Es=="NOR_1993"]=6
dt$NP[dt$Es=="NOR_1997"]=6
dt$NP[dt$Es=="NOR_2005"]=6
dt$NP[dt$Es=="PRT_2002"]=6
dt$NP[dt$Es=="PRT_2009"]=5
dt$NP[dt$Es=="SWE_1982"]=5
dt$NP[dt$Es=="SWE_1985"]=6
dt$NP[dt$Es=="SWE_1988"]=5
dt$NP[dt$Es=="SWE_1991"]=6
dt$NP[dt$Es=="SWE_1994"]=6
dt$NP[dt$Es=="SWE_1998"]=6
dt$NP[dt$Es=="SWE_2006"]=6


#CoalCode:----
dt$CoalCode=NA
dt$CoalCode[dt$Es=="ESP_1979"]=0
dt$CoalCode[dt$Es=="ESP_1982"]=0
dt$CoalCode[dt$Es=="ESP_1993"]=0
dt$CoalCode[dt$Es=="ESP_2004"]=0
dt$CoalCode[dt$Es=="EST_2011"]=0
dt$CoalCode[dt$Es=="FIN_2003"]=0
dt$CoalCode[dt$Es=="GBR_2005"]=0
dt$CoalCode[dt$Es=="GRC_1985"]=0
dt$CoalCode[dt$Es=="GRC_1990"]=1
dt$CoalCode[dt$Es=="GRC_1990"]=0
dt$CoalCode[dt$Es=="GRC_1996"]=0
dt$CoalCode[dt$Es=="GRC_2000"]=0
dt$CoalCode[dt$Es=="GRC_2004"]=0
dt$CoalCode[dt$Es=="GRC_2007"]=0
dt$CoalCode[dt$Es=="HUN_1998"]=0
dt$CoalCode[dt$Es=="HUN_2006"]=0
dt$CoalCode[dt$Es=="IRL_2002"]=0
dt$CoalCode[dt$Es=="ISL_1987"]=0
dt$CoalCode[dt$Es=="ISL_1991"]=0
dt$CoalCode[dt$Es=="ISL_1995"]=0
dt$CoalCode[dt$Es=="ISL_2003"]=0
dt$CoalCode[dt$Es=="ITA_2006"]=1
dt$CoalCode[dt$Es=="ITA_2008"]=1
dt$CoalCode[dt$Es=="LTU_2000"]=0
dt$CoalCode[dt$Es=="NLD_2002"]=0
dt$CoalCode[dt$Es=="NOR_2001"]=0
dt$CoalCode[dt$Es=="PRT_2005"]=0
dt$CoalCode[dt$Es=="SVN_2000"]=0
dt$CoalCode[dt$Es=="SWE_1979"]=0
dt$CoalCode[dt$Es=="SWE_2002"]=0
dt$CoalCode[dt$Es=="SWE_2010"]=0

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$CoalCode[dt$Es=="DEU_1961"]=1
dt$CoalCode[dt$Es=="DEU_1965"]=1
dt$CoalCode[dt$Es=="DEU_1976"]=1
dt$CoalCode[dt$Es=="DEU_1980"]=1
dt$CoalCode[dt$Es=="DEU_1983"]=1
dt$CoalCode[dt$Es=="DEU_1987"]=1
dt$CoalCode[dt$Es=="DEU_1990"]=1
dt$CoalCode[dt$Es=="DEU_1994"]=1
dt$CoalCode[dt$Es=="DEU_1998"]=1
dt$CoalCode[dt$Es=="DEU_2009"]=1
dt$CoalCode[dt$Es=="DEU_2013"]=1
dt$CoalCode[dt$Es=="FIN_2007"]=0
dt$CoalCode[dt$Es=="FIN_2011"]=0
dt$CoalCode[dt$Es=="GRC_2009"]=0
dt$CoalCode[dt$Es=="GRC_2012"]=0
dt$CoalCode[dt$Es=="IRL_2007"]=0
dt$CoalCode[dt$Es=="IRL_2011"]=0
dt$CoalCode[dt$Es=="ISL_1999"]=0
dt$CoalCode[dt$Es=="ISL_2007"]=0
dt$CoalCode[dt$Es=="ISL_2009"]=0
dt$CoalCode[dt$Es=="ISL_2013"]=0
dt$CoalCode[dt$Es=="NLD_1994"]=0
dt$CoalCode[dt$Es=="NLD_1998"]=0
dt$CoalCode[dt$Es=="NOR_1981"]=0
dt$CoalCode[dt$Es=="NOR_1985"]=0
dt$CoalCode[dt$Es=="NOR_1989"]=0
dt$CoalCode[dt$Es=="NOR_1993"]=0
dt$CoalCode[dt$Es=="NOR_1997"]=0
dt$CoalCode[dt$Es=="NOR_2005"]=0
dt$CoalCode[dt$Es=="PRT_2002"]=0
dt$CoalCode[dt$Es=="PRT_2009"]=0
dt$CoalCode[dt$Es=="SWE_1982"]=0
dt$CoalCode[dt$Es=="SWE_1985"]=0
dt$CoalCode[dt$Es=="SWE_1988"]=0
dt$CoalCode[dt$Es=="SWE_1991"]=0
dt$CoalCode[dt$Es=="SWE_1994"]=0
dt$CoalCode[dt$Es=="SWE_1998"]=0
dt$CoalCode[dt$Es=="SWE_2006"]=0


#Rwd demographic weights:----

dt$OWEIGHT1[dt$OWEIGHT1==999]=1#non coded weight in elections to NA
dt$OWEIGHT2[dt$OWEIGHT2==999]=1
dt$OWEIGHT3[dt$OWEIGHT3==999]=1
dt$OWEIGHT4[dt$OWEIGHT4==999]=1
dt$OWEIGHT1[dt$OWEIGHT1==0]=1#missing respondent weight put to neutral weight of 1
dt$OWEIGHT2[dt$OWEIGHT2==0]=1
dt$OWEIGHT3[dt$OWEIGHT3==0]=1
dt$OWEIGHT4[dt$OWEIGHT4==0]=1
summary(dt$OWEIGHT1)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0593  1.0000  1.0000  1.0102  1.0000 12.6207
```

``` r
summary(dt$OWEIGHT2)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.020   1.000   1.000   1.007   1.000   9.025
```

``` r
summary(dt$OWEIGHT3)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.2077  1.0000  1.0000  1.0024  1.0000  5.1965
```

``` r
summary(dt$OWEIGHT4)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.36    1.00    1.00    1.00    1.00    3.53
```

``` r
#code election specific weights:
dt$Rwd=1#Respondent Weight Demographic:
dt$Rwd[dt$Es=="DEU_1961"]=dt$OWEIGHT1[dt$Es=="DEU_1961"]
dt$Rwd[dt$Es=="DEU_1965"]=dt$OWEIGHT1[dt$Es=="DEU_1965"]
dt$Rwd[dt$Es=="DEU_1976"]=dt$OWEIGHT1[dt$Es=="DEU_1976"]
dt$Rwd[dt$Es=="DEU_1980"]=dt$OWEIGHT2[dt$Es=="DEU_1980"]
dt$Rwd[dt$Es=="DEU_1983"]=dt$OWEIGHT2[dt$Es=="DEU_1983"]
dt$Rwd[dt$Es=="DEU_1987"]=dt$OWEIGHT4[dt$Es=="DEU_1987"]
dt$Rwd[dt$Es=="DEU_1990"]=dt$OWEIGHT2[dt$Es=="DEU_1990"]
dt$Rwd[dt$Es=="DEU_1994"]=dt$OWEIGHT1[dt$Es=="DEU_1994"]
dt$Rwd[dt$Es=="DEU_1998"]=dt$OWEIGHT1[dt$Es=="DEU_1998"]
dt$Rwd[dt$Es=="DEU_2009"]=dt$OWEIGHT2[dt$Es=="DEU_2009"]
dt$Rwd[dt$Es=="DEU_2013"]=dt$OWEIGHT2[dt$Es=="DEU_2013"]
dt$Rwd[dt$Es=="ESP_1979"]=dt$OWEIGHT1[dt$Es=="ESP_1979"]
dt$Rwd[dt$Es=="ESP_1982"]=dt$OWEIGHT1[dt$Es=="ESP_1982"]
dt$Rwd[dt$Es=="FIN_2003"]=dt$OWEIGHT1[dt$Es=="FIN_2003"]
dt$Rwd[dt$Es=="FIN_2007"]=dt$OWEIGHT1[dt$Es=="FIN_2007"]
dt$Rwd[dt$Es=="GBR_2005"]=dt$OWEIGHT1[dt$Es=="GBR_2005"]
dt$Rwd[dt$Es=="IRL_2002"]=dt$OWEIGHT1[dt$Es=="IRL_2002"]
dt$Rwd[dt$Es=="ISL_1987"]=dt$OWEIGHT1[dt$Es=="ISL_1987"]
dt$Rwd[dt$Es=="PRT_2005"]=dt$OWEIGHT4[dt$Es=="PRT_2005"]


#Party family voted party:----
colnames(dt)[colnames(dt)=="CMPPRT"]="CMPid"#CMP party codes for party R voted for

#read CMP data and party Id match CSES-CMP:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

dCMP=dCMP[,c(7,10)]#filter data and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid"
colnames(dCMP)[colnames(dCMP)=="parfam"]="Pf"
dCMP=dCMP[!duplicated(dCMP$CMPid),]

#code party family vote choice (VPf):
dt=merge(dt, dCMP, by = c("CMPid"), all.x=T)
colnames(dt)[colnames(dt)=="Pf"]="VPf"
# dt=dt[,-which(names(dt) %in% c("CMPid"))]


#CMPid.i:----

dt$CMPid.1=NA#create Pl:
dt$CMPid.2=NA
dt$CMPid.3=NA
dt$CMPid.4=NA
dt$CMPid.5=NA
dt$CMPid.6=NA

dt$CMPid.1[dt$Es=="ESP_1979"]=33430#assign CMPid by party size order for parties with likability:
dt$CMPid.2[dt$Es=="ESP_1979"]=33320
dt$CMPid.3[dt$Es=="ESP_1979"]=33220
dt$CMPid.4[dt$Es=="ESP_1979"]=33610

dt$CMPid.1[dt$Es=="ESP_1982"]=33320
dt$CMPid.2[dt$Es=="ESP_1982"]=33610
dt$CMPid.3[dt$Es=="ESP_1982"]=33430
dt$CMPid.4[dt$Es=="ESP_1982"]=33220
dt$CMPid.5[dt$Es=="ESP_1982"]=33512

dt$CMPid.1[dt$Es=="ESP_1993"]=33320
dt$CMPid.2[dt$Es=="ESP_1993"]=33610
dt$CMPid.3[dt$Es=="ESP_1993"]=33220
dt$CMPid.4[dt$Es=="ESP_1993"]=33512

dt$CMPid.1[dt$Es=="ESP_2004"]=33320
dt$CMPid.2[dt$Es=="ESP_2004"]=33610
dt$CMPid.3[dt$Es=="ESP_2004"]=33220

dt$CMPid.1[dt$Es=="EST_2011"]=83430
dt$CMPid.2[dt$Es=="EST_2011"]=83411
dt$CMPid.3[dt$Es=="EST_2011"]=83611
dt$CMPid.4[dt$Es=="EST_2011"]=83410
dt$CMPid.5[dt$Es=="EST_2011"]=83110
dt$CMPid.6[dt$Es=="EST_2011"]=83612

dt$CMPid.1[dt$Es=="FIN_2003"]=14810
dt$CMPid.2[dt$Es=="FIN_2003"]=14320
dt$CMPid.3[dt$Es=="FIN_2003"]=14620
dt$CMPid.4[dt$Es=="FIN_2003"]=14223
dt$CMPid.5[dt$Es=="FIN_2003"]=14110
dt$CMPid.6[dt$Es=="FIN_2003"]=14901

dt$CMPid.1[dt$Es=="GBR_2005"]=51320
dt$CMPid.2[dt$Es=="GBR_2005"]=51620
dt$CMPid.3[dt$Es=="GBR_2005"]=51421

dt$CMPid.1[dt$Es=="GRC_1985"]=34313
dt$CMPid.2[dt$Es=="GRC_1985"]=34511
dt$CMPid.3[dt$Es=="GRC_1985"]=34210
dt$CMPid.4[dt$Es=="GRC_1985"]=99990

dt$CMPid.1[dt$Es=="GRC_1989"]=34511
dt$CMPid.2[dt$Es=="GRC_1989"]=34313
dt$CMPid.3[dt$Es=="GRC_1989"]=34211

dt$CMPid.1[dt$Es=="GRC_1990"]=34511
dt$CMPid.2[dt$Es=="GRC_1990"]=34313
dt$CMPid.3[dt$Es=="GRC_1990"]=34211

dt$CMPid.1[dt$Es=="GRC_1996"]=34313
dt$CMPid.2[dt$Es=="GRC_1996"]=34511
dt$CMPid.3[dt$Es=="GRC_1996"]=34210
dt$CMPid.4[dt$Es=="GRC_1996"]=34211
dt$CMPid.5[dt$Es=="GRC_1996"]=34314

dt$CMPid.1[dt$Es=="GRC_2000"]=34313
dt$CMPid.2[dt$Es=="GRC_2000"]=34511
dt$CMPid.3[dt$Es=="GRC_2000"]=34210
dt$CMPid.4[dt$Es=="GRC_2000"]=34211

dt$CMPid.1[dt$Es=="GRC_2004"]=34511
dt$CMPid.2[dt$Es=="GRC_2004"]=34313
dt$CMPid.3[dt$Es=="GRC_2004"]=34210
dt$CMPid.4[dt$Es=="GRC_2004"]=34020

dt$CMPid.1[dt$Es=="GRC_2007"]=34511
dt$CMPid.2[dt$Es=="GRC_2007"]=34313
dt$CMPid.3[dt$Es=="GRC_2007"]=34210
dt$CMPid.4[dt$Es=="GRC_2007"]=34020
dt$CMPid.5[dt$Es=="GRC_2007"]=34710

dt$CMPid.1[dt$Es=="HUN_1998"]=86429
dt$CMPid.2[dt$Es=="HUN_1998"]=86220
dt$CMPid.3[dt$Es=="HUN_1998"]=86810
dt$CMPid.4[dt$Es=="HUN_1998"]=86422
dt$CMPid.5[dt$Es=="HUN_1998"]=86521
dt$CMPid.6[dt$Es=="HUN_1998"]=86620

dt$CMPid.1[dt$Es=="HUN_2006"]=86220
dt$CMPid.2[dt$Es=="HUN_2006"]=86061
dt$CMPid.3[dt$Es=="HUN_2006"]=86422
dt$CMPid.4[dt$Es=="HUN_2006"]=86521

dt$CMPid.1[dt$Es=="IRL_2002"]=53620
dt$CMPid.2[dt$Es=="IRL_2002"]=53520
dt$CMPid.3[dt$Es=="IRL_2002"]=53320
dt$CMPid.4[dt$Es=="IRL_2002"]=53420
dt$CMPid.5[dt$Es=="IRL_2002"]=53110
dt$CMPid.6[dt$Es=="IRL_2002"]=53951

dt$CMPid.1[dt$Es=="ISL_1987"]=15620
dt$CMPid.2[dt$Es=="ISL_1987"]=15810
dt$CMPid.3[dt$Es=="ISL_1987"]=15320
dt$CMPid.4[dt$Es=="ISL_1987"]=15220
dt$CMPid.5[dt$Es=="ISL_1987"]=15621

dt$CMPid.1[dt$Es=="ISL_1991"]=15620
dt$CMPid.2[dt$Es=="ISL_1991"]=15810
dt$CMPid.3[dt$Es=="ISL_1991"]=15320
dt$CMPid.4[dt$Es=="ISL_1991"]=15220
dt$CMPid.5[dt$Es=="ISL_1991"]=15951

dt$CMPid.1[dt$Es=="ISL_1995"]=15620
dt$CMPid.2[dt$Es=="ISL_1995"]=15810
dt$CMPid.3[dt$Es=="ISL_1995"]=15220
dt$CMPid.4[dt$Es=="ISL_1995"]=15320
dt$CMPid.5[dt$Es=="ISL_1995"]=15323
dt$CMPid.6[dt$Es=="ISL_1995"]=15951

dt$CMPid.1[dt$Es=="ISL_2003"]=15620
dt$CMPid.2[dt$Es=="ISL_2003"]=15328
dt$CMPid.3[dt$Es=="ISL_2003"]=15810
dt$CMPid.4[dt$Es=="ISL_2003"]=15111
dt$CMPid.5[dt$Es=="ISL_2003"]=15420

dt$CMPid.1[dt$Es=="ITA_2006"]=32329#coalition==1
dt$CMPid.2[dt$Es=="ITA_2006"]=32610
dt$CMPid.3[dt$Es=="ITA_2006"]=32710
dt$CMPid.4[dt$Es=="ITA_2006"]=32530
dt$CMPid.5[dt$Es=="ITA_2006"]=32212
dt$CMPid.6[dt$Es=="ITA_2006"]=32720

dt$CMPid.1[dt$Es=="ITA_2008"]=32061#coalition==1
dt$CMPid.2[dt$Es=="ITA_2008"]=32440
dt$CMPid.3[dt$Es=="ITA_2008"]=32720
dt$CMPid.4[dt$Es=="ITA_2008"]=32530
dt$CMPid.5[dt$Es=="ITA_2008"]=32902
dt$CMPid.6[dt$Es=="ITA_2008"]=99991

dt$CMPid.1[dt$Es=="LTU_2000"]=88410
dt$CMPid.2[dt$Es=="LTU_2000"]=88422
dt$CMPid.3[dt$Es=="LTU_2000"]=88321
dt$CMPid.4[dt$Es=="LTU_2000"]=88620

dt$CMPid.1[dt$Es=="NLD_2002"]=22521
dt$CMPid.2[dt$Es=="NLD_2002"]=22720
dt$CMPid.3[dt$Es=="NLD_2002"]=22420
dt$CMPid.4[dt$Es=="NLD_2002"]=22320
dt$CMPid.5[dt$Es=="NLD_2002"]=22110
dt$CMPid.6[dt$Es=="NLD_2002"]=22220

dt$CMPid.1[dt$Es=="NOR_2001"]=12320
dt$CMPid.2[dt$Es=="NOR_2001"]=12620
dt$CMPid.3[dt$Es=="NOR_2001"]=12951
dt$CMPid.4[dt$Es=="NOR_2001"]=12221
dt$CMPid.5[dt$Es=="NOR_2001"]=12520
dt$CMPid.6[dt$Es=="NOR_2001"]=12810

dt$CMPid.1[dt$Es=="PRT_2005"]=35311
dt$CMPid.2[dt$Es=="PRT_2005"]=35313
dt$CMPid.3[dt$Es=="PRT_2005"]=35220#CMP codes the communist party instead than the coalition
dt$CMPid.4[dt$Es=="PRT_2005"]=35520
dt$CMPid.5[dt$Es=="PRT_2005"]=35211

dt$CMPid.1[dt$Es=="SVN_2000"]=97421
dt$CMPid.2[dt$Es=="SVN_2000"]=97330
dt$CMPid.3[dt$Es=="SVN_2000"]=97321
dt$CMPid.4[dt$Es=="SVN_2000"]=97521
dt$CMPid.5[dt$Es=="SVN_2000"]=97522
dt$CMPid.6[dt$Es=="SVN_2000"]=97951

dt$CMPid.1[dt$Es=="SWE_1979"]=11320
dt$CMPid.2[dt$Es=="SWE_1979"]=11620
dt$CMPid.3[dt$Es=="SWE_1979"]=11810
dt$CMPid.4[dt$Es=="SWE_1979"]=11420
dt$CMPid.5[dt$Es=="SWE_1979"]=11220

dt$CMPid.1[dt$Es=="SWE_2002"]=11320
dt$CMPid.2[dt$Es=="SWE_2002"]=11620
dt$CMPid.3[dt$Es=="SWE_2002"]=11420
dt$CMPid.4[dt$Es=="SWE_2002"]=11520
dt$CMPid.5[dt$Es=="SWE_2002"]=11220
dt$CMPid.6[dt$Es=="SWE_2002"]=11810

dt$CMPid.1[dt$Es=="SWE_2010"]=11320
dt$CMPid.2[dt$Es=="SWE_2010"]=11620
dt$CMPid.3[dt$Es=="SWE_2010"]=11110
dt$CMPid.4[dt$Es=="SWE_2010"]=11420
dt$CMPid.5[dt$Es=="SWE_2010"]=11810
dt$CMPid.6[dt$Es=="SWE_2010"]=11710

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$CMPid.1[dt$Es=="DEU_1961"]=41521
dt$CMPid.2[dt$Es=="DEU_1961"]=41320
dt$CMPid.3[dt$Es=="DEU_1961"]=41420

dt$CMPid.1[dt$Es=="DEU_1965"]=41521
dt$CMPid.2[dt$Es=="DEU_1965"]=41320
dt$CMPid.3[dt$Es=="DEU_1965"]=41420

dt$CMPid.1[dt$Es=="DEU_1976"]=41521
dt$CMPid.2[dt$Es=="DEU_1976"]=41320
dt$CMPid.3[dt$Es=="DEU_1976"]=41420

dt$CMPid.1[dt$Es=="DEU_1980"]=41521
dt$CMPid.2[dt$Es=="DEU_1980"]=41320
dt$CMPid.3[dt$Es=="DEU_1980"]=41420

dt$CMPid.1[dt$Es=="DEU_1983"]=41521
dt$CMPid.2[dt$Es=="DEU_1983"]=41320
dt$CMPid.3[dt$Es=="DEU_1983"]=41420

dt$CMPid.1[dt$Es=="DEU_1987"]=41521
dt$CMPid.2[dt$Es=="DEU_1987"]=41320
dt$CMPid.3[dt$Es=="DEU_1987"]=41420

dt$CMPid.1[dt$Es=="DEU_1990"]=41521
dt$CMPid.2[dt$Es=="DEU_1990"]=41320
dt$CMPid.3[dt$Es=="DEU_1990"]=41420
#CMP coded Party of Democratic Socialism while TEV coded The Left / Gysi, correct is CMP:
dt$CMPid.4[dt$Es=="DEU_1990"]=41221#

dt$CMPid.1[dt$Es=="DEU_1994"]=41521
dt$CMPid.2[dt$Es=="DEU_1994"]=41320
dt$CMPid.3[dt$Es=="DEU_1994"]=41113
dt$CMPid.4[dt$Es=="DEU_1994"]=41420
#CMP coded Party of Democratic Socialism while TEV coded The Left / Gysi, correct is CMP:
dt$CMPid.5[dt$Es=="DEU_1994"]=41221#

dt$CMPid.1[dt$Es=="DEU_1998"]=41320
dt$CMPid.2[dt$Es=="DEU_1998"]=41521
dt$CMPid.3[dt$Es=="DEU_1998"]=41113
dt$CMPid.4[dt$Es=="DEU_1998"]=41420
#CMP coded Party of Democratic Socialism while TEV coded The Left / Gysi, correct is CMP:
dt$CMPid.5[dt$Es=="DEU_1998"]=41221#

dt$CMPid.1[dt$Es=="DEU_2009"]=41521
dt$CMPid.2[dt$Es=="DEU_2009"]=41320
dt$CMPid.3[dt$Es=="DEU_2009"]=41420
dt$CMPid.4[dt$Es=="DEU_2009"]=41223
dt$CMPid.5[dt$Es=="DEU_2009"]=41113

dt$CMPid.1[dt$Es=="DEU_2013"]=41521
dt$CMPid.2[dt$Es=="DEU_2013"]=41320
dt$CMPid.3[dt$Es=="DEU_2013"]=41223
dt$CMPid.4[dt$Es=="DEU_2013"]=41113
dt$CMPid.5[dt$Es=="DEU_2013"]=41420

dt$CMPid.1[dt$Es=="FIN_2007"]=14810
dt$CMPid.2[dt$Es=="FIN_2007"]=14620
dt$CMPid.3[dt$Es=="FIN_2007"]=14320
dt$CMPid.4[dt$Es=="FIN_2007"]=14223
dt$CMPid.5[dt$Es=="FIN_2007"]=14110
dt$CMPid.6[dt$Es=="FIN_2007"]=14520

dt$CMPid.1[dt$Es=="FIN_2011"]=14620
dt$CMPid.2[dt$Es=="FIN_2011"]=14320
dt$CMPid.3[dt$Es=="FIN_2011"]=14820
dt$CMPid.4[dt$Es=="FIN_2011"]=14810
dt$CMPid.5[dt$Es=="FIN_2011"]=14223
dt$CMPid.6[dt$Es=="FIN_2011"]=14110

dt$CMPid.1[dt$Es=="GRC_2009"]=34313
dt$CMPid.2[dt$Es=="GRC_2009"]=34511
dt$CMPid.3[dt$Es=="GRC_2009"]=34210
dt$CMPid.4[dt$Es=="GRC_2009"]=34710
dt$CMPid.5[dt$Es=="GRC_2009"]=34020
dt$CMPid.6[dt$Es=="GRC_2009"]=99990

dt$CMPid.1[dt$Es=="GRC_2012"]=34511
dt$CMPid.2[dt$Es=="GRC_2012"]=34212
dt$CMPid.3[dt$Es=="GRC_2012"]=34313
dt$CMPid.4[dt$Es=="GRC_2012"]=34730
dt$CMPid.5[dt$Es=="GRC_2012"]=34720
dt$CMPid.6[dt$Es=="GRC_2012"]=34213

dt$CMPid.1[dt$Es=="IRL_2007"]=53620
dt$CMPid.2[dt$Es=="IRL_2007"]=53520
dt$CMPid.3[dt$Es=="IRL_2007"]=53320
dt$CMPid.4[dt$Es=="IRL_2007"]=53110
dt$CMPid.5[dt$Es=="IRL_2007"]=53951
dt$CMPid.6[dt$Es=="IRL_2007"]=53420

dt$CMPid.1[dt$Es=="IRL_2011"]=53520
dt$CMPid.2[dt$Es=="IRL_2011"]=53320
dt$CMPid.3[dt$Es=="IRL_2011"]=53620
dt$CMPid.4[dt$Es=="IRL_2011"]=53951
dt$CMPid.5[dt$Es=="IRL_2011"]=53110#

dt$CMPid.1[dt$Es=="ISL_1999"]=15620
dt$CMPid.2[dt$Es=="ISL_1999"]=15328
dt$CMPid.3[dt$Es=="ISL_1999"]=15810
dt$CMPid.4[dt$Es=="ISL_1999"]=15111
dt$CMPid.5[dt$Es=="ISL_1999"]=15420

dt$CMPid.1[dt$Es=="ISL_2007"]=15620
dt$CMPid.2[dt$Es=="ISL_2007"]=15328
dt$CMPid.3[dt$Es=="ISL_2007"]=15111
dt$CMPid.4[dt$Es=="ISL_2007"]=15810
dt$CMPid.5[dt$Es=="ISL_2007"]=15420
dt$CMPid.6[dt$Es=="ISL_2007"]=99990#

dt$CMPid.1[dt$Es=="ISL_2009"]=15328
dt$CMPid.2[dt$Es=="ISL_2009"]=15620
dt$CMPid.3[dt$Es=="ISL_2009"]=15111
dt$CMPid.4[dt$Es=="ISL_2009"]=15810
dt$CMPid.5[dt$Es=="ISL_2009"]=15420#
dt$CMPid.6[dt$Es=="ISL_2009"]=15430#

dt$CMPid.1[dt$Es=="ISL_2013"]=15620
dt$CMPid.2[dt$Es=="ISL_2013"]=15810
dt$CMPid.3[dt$Es=="ISL_2013"]=15328
dt$CMPid.4[dt$Es=="ISL_2013"]=15111
dt$CMPid.5[dt$Es=="ISL_2013"]=15440
dt$CMPid.6[dt$Es=="ISL_2013"]=15952

dt$CMPid.1[dt$Es=="NLD_1994"]=22320
dt$CMPid.2[dt$Es=="NLD_1994"]=22521
dt$CMPid.3[dt$Es=="NLD_1994"]=22420
dt$CMPid.4[dt$Es=="NLD_1994"]=22330

dt$CMPid.1[dt$Es=="NLD_1998"]=22320#EV 4 parties, CSES 6 parties coded
dt$CMPid.2[dt$Es=="NLD_1998"]=22420
dt$CMPid.3[dt$Es=="NLD_1998"]=22521
dt$CMPid.4[dt$Es=="NLD_1998"]=22330
dt$CMPid.5[dt$Es=="NLD_1998"]=22110
dt$CMPid.6[dt$Es=="NLD_1998"]=22527#

dt$CMPid.1[dt$Es=="NOR_1981"]=12320
dt$CMPid.2[dt$Es=="NOR_1981"]=12620
dt$CMPid.3[dt$Es=="NOR_1981"]=12520
dt$CMPid.4[dt$Es=="NOR_1981"]=12810
dt$CMPid.5[dt$Es=="NOR_1981"]=12221
dt$CMPid.6[dt$Es=="NOR_1981"]=12951

dt$CMPid.1[dt$Es=="NOR_1985"]=12320
dt$CMPid.2[dt$Es=="NOR_1985"]=12620
dt$CMPid.3[dt$Es=="NOR_1985"]=12520
dt$CMPid.4[dt$Es=="NOR_1985"]=12810
dt$CMPid.5[dt$Es=="NOR_1985"]=12221
dt$CMPid.6[dt$Es=="NOR_1985"]=12951

dt$CMPid.1[dt$Es=="NOR_1989"]=12320
dt$CMPid.2[dt$Es=="NOR_1989"]=12620
dt$CMPid.3[dt$Es=="NOR_1989"]=12951
dt$CMPid.4[dt$Es=="NOR_1989"]=12221
dt$CMPid.5[dt$Es=="NOR_1989"]=12520
dt$CMPid.6[dt$Es=="NOR_1989"]=12810

dt$CMPid.1[dt$Es=="NOR_1993"]=12320
dt$CMPid.2[dt$Es=="NOR_1993"]=12810
dt$CMPid.3[dt$Es=="NOR_1993"]=12620
dt$CMPid.4[dt$Es=="NOR_1993"]=12221
dt$CMPid.5[dt$Es=="NOR_1993"]=12520
dt$CMPid.6[dt$Es=="NOR_1993"]=12951

dt$CMPid.1[dt$Es=="NOR_1997"]=12320
dt$CMPid.2[dt$Es=="NOR_1997"]=12951
dt$CMPid.3[dt$Es=="NOR_1997"]=12520
dt$CMPid.4[dt$Es=="NOR_1997"]=12620
dt$CMPid.5[dt$Es=="NOR_1997"]=12810
dt$CMPid.6[dt$Es=="NOR_1997"]=12221

dt$CMPid.1[dt$Es=="NOR_2005"]=12320
dt$CMPid.2[dt$Es=="NOR_2005"]=12951
dt$CMPid.3[dt$Es=="NOR_2005"]=12620
dt$CMPid.4[dt$Es=="NOR_2005"]=12221
dt$CMPid.5[dt$Es=="NOR_2005"]=12520
dt$CMPid.6[dt$Es=="NOR_2005"]=12810

dt$CMPid.1[dt$Es=="PRT_2002"]=35313
dt$CMPid.2[dt$Es=="PRT_2002"]=35311
dt$CMPid.3[dt$Es=="PRT_2002"]=35520
dt$CMPid.4[dt$Es=="PRT_2002"]=35220#CMP codes the communist party instead than the coalition
dt$CMPid.5[dt$Es=="PRT_2002"]=35211
dt$CMPid.6[dt$Es=="PRT_2002"]=99990

dt$CMPid.1[dt$Es=="PRT_2009"]=35311#osym4-5  inverted!?
dt$CMPid.2[dt$Es=="PRT_2009"]=35313
dt$CMPid.3[dt$Es=="PRT_2009"]=35520
dt$CMPid.4[dt$Es=="PRT_2009"]=35211
dt$CMPid.5[dt$Es=="PRT_2009"]=35220#CMP codes the communist party instead than the coalition

dt$CMPid.1[dt$Es=="SWE_1982"]=11320
dt$CMPid.2[dt$Es=="SWE_1982"]=11620
dt$CMPid.3[dt$Es=="SWE_1982"]=11810
dt$CMPid.4[dt$Es=="SWE_1982"]=11420
dt$CMPid.5[dt$Es=="SWE_1982"]=11220

dt$CMPid.1[dt$Es=="SWE_1985"]=11320
dt$CMPid.2[dt$Es=="SWE_1985"]=11620
dt$CMPid.3[dt$Es=="SWE_1985"]=11420
dt$CMPid.4[dt$Es=="SWE_1985"]=11810
dt$CMPid.5[dt$Es=="SWE_1985"]=11220
dt$CMPid.6[dt$Es=="SWE_1985"]=11520

dt$CMPid.1[dt$Es=="SWE_1988"]=11320
dt$CMPid.2[dt$Es=="SWE_1988"]=11620
dt$CMPid.3[dt$Es=="SWE_1988"]=11420
dt$CMPid.4[dt$Es=="SWE_1988"]=11810
dt$CMPid.5[dt$Es=="SWE_1988"]=11220

dt$CMPid.1[dt$Es=="SWE_1991"]=11320
dt$CMPid.2[dt$Es=="SWE_1991"]=11620
dt$CMPid.3[dt$Es=="SWE_1991"]=11420
dt$CMPid.4[dt$Es=="SWE_1991"]=11810
dt$CMPid.5[dt$Es=="SWE_1991"]=11520
dt$CMPid.6[dt$Es=="SWE_1991"]=11951

dt$CMPid.1[dt$Es=="SWE_1994"]=11320
dt$CMPid.2[dt$Es=="SWE_1994"]=11620
dt$CMPid.3[dt$Es=="SWE_1994"]=11810
dt$CMPid.4[dt$Es=="SWE_1994"]=11420
dt$CMPid.5[dt$Es=="SWE_1994"]=11220
dt$CMPid.6[dt$Es=="SWE_1994"]=11110

dt$CMPid.1[dt$Es=="SWE_1998"]=11320
dt$CMPid.2[dt$Es=="SWE_1998"]=11620
dt$CMPid.3[dt$Es=="SWE_1998"]=11220
dt$CMPid.4[dt$Es=="SWE_1998"]=11520
dt$CMPid.5[dt$Es=="SWE_1998"]=11810
dt$CMPid.6[dt$Es=="SWE_1998"]=11420

dt$CMPid.1[dt$Es=="SWE_2006"]=11320
dt$CMPid.2[dt$Es=="SWE_2006"]=11620
dt$CMPid.3[dt$Es=="SWE_2006"]=11810
dt$CMPid.4[dt$Es=="SWE_2006"]=11420
dt$CMPid.5[dt$Es=="SWE_2006"]=11520
dt$CMPid.6[dt$Es=="SWE_2006"]=11220

dt$CMPid.1=as.numeric(dt$CMPid.1)#recode as numeric:
dt$CMPid.2=as.numeric(dt$CMPid.2)
dt$CMPid.3=as.numeric(dt$CMPid.3)
dt$CMPid.4=as.numeric(dt$CMPid.4)
dt$CMPid.5=as.numeric(dt$CMPid.5)
dt$CMPid.6=as.numeric(dt$CMPid.6)


#Pv.i (pervote):----

#NB: TEV coded pervote in the "stacked" dataset, but it is impossible to recover that data,
# thus I recode pervote from the CMP dataset via CMPid, country, year.

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="pervote"]="Pv"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

#GRC_2012: there was an election one month before in may, need to exclude it from dCMP
# to merge in dt only the parties in the June election (which is the one coded by TEV):
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==201205),]
#same for GRC_1989: I excluded the June election because there are less than three parties coded,
# and need to exclude it from DCMP:
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==198906),]

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,16)]

#code pervote alternative i (Pv.i):
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T, all.y=F)
colnames(dt)[colnames(dt)=="Pv"]="Pv.1"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Pv"]="Pv.2"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Pv"]="Pv.3"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Pv"]="Pv.4"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Pv"]="Pv.5"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Pv"]="Pv.6"

#recode Pv.i not coded in CMP:
#TEV coded Icelandic Movement (IM) / Ómar Ragnarsson but CMP did not assign vote:
dt$Pv.6[dt$Es=="ISL_2007"]=5.95
#TEV coded Liberal Party (LP) / Guðjón Arnar Kristjánsson but CMP did not assign vote:
dt$Pv.5[dt$Es=="ISL_2009"]=4.14
#TEV coded Communist Party of Greece (interior) KKEes / Kyrkos but CMP did not assign vote:
dt$Pv.4[dt$Es=="GRC_1985"]=0.1
#TEV coded Ecologists-Greens (OP) / Xrisogelos but CMP did not assign vote:
dt$Pv.6[dt$Es=="GRC_2009"]=2.53
#TEV coded The Left – The rainbow (SA) / Fausto Bertinotti but CMP did not assign vote:
dt$Pv.6[dt$Es=="ITA_2008"]=3.08
#TEV coded Portuguese Workers' Communist Party (PCTP/MRPP) / Garcia Pereira but CMP did not assign vote:
dt$Pv.6[dt$Es=="PRT_2002"]=0.66


#Ps.i (perseats):----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="absseat"]="Ps"
colnames(dCMP)[colnames(dCMP)=="totseats"]="Pst"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

#GRC_2012: there was an election one month before in may, need to exclude it from dCMP
# to merge in dt only the parties in the june election (which is the one coded by TEV):
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==201205),]
#same for GRC_1989: I excluded the June election because there are less than three parties coded,
# and need to exclude it from DCMP:
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==198906),]

#code total seats:
dCMP_temp=dCMP[,c(175,176,7,20)]
dt=merge(dt, dCMP_temp, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
# #check:
# summary(dt$CMPid.1)
# summary(dt$Pst)
# sort(unique(dt$Es[is.na(dt$Pst)]))
rm(dCMP_temp)

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,19)]

#code pervote alternative i (Ps.i):
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.1"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.2"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.3"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.4"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.5"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="Ps"]="Ps.6"

#recode Ps.i not coded in CMP:
#TEV coded Icelandic Movement (IM) / Ómar Ragnarsson but CMP did not assign seats:
dt$Ps.6[dt$Es=="ISL_2007"]=0
#TEV coded Liberal Party (LP) / Guðjón Arnar Kristjánsson but CMP did not assign seats:
dt$Ps.5[dt$Es=="ISL_2009"]=0
#TEV coded Communist Party of Greece (interior) KKEes / Kyrkos but CMP did not assign seats:
dt$Ps.4[dt$Es=="GRC_1985"]=1
#TEV coded Ecologists-Greens (OP) / Xrisogelos but CMP did not assign seats:
dt$Ps.6[dt$Es=="GRC_2009"]=0
#TEV coded The Left – The rainbow (SA) / Fausto Bertinotti but CMP did not assign seats:
dt$Ps.6[dt$Es=="ITA_2008"]=0
#TEV coded Portuguese Workers' Communist Party (PCTP/MRPP) / Garcia Pereira but CMP did not assign seats:
dt$Ps.6[dt$Es=="PRT_2002"]=0


#get seat share %:
dt$Ps.1=dt$Ps.1/dt$Pst*100
dt$Ps.2=dt$Ps.2/dt$Pst*100
dt$Ps.3=dt$Ps.3/dt$Pst*100
dt$Ps.4=dt$Ps.4/dt$Pst*100
dt$Ps.5=dt$Ps.5/dt$Pst*100
dt$Ps.6=dt$Ps.6/dt$Pst*100


#Seats to vote ratios:----
dt$P1SVrat=dt$Ps.1/dt$Pv.1#for most voted party
dt$P2SVrat=dt$Ps.2/dt$Pv.2#for second most voted party
dt$P1P2rat=dt$P1SVrat/dt$P2SVrat#ratio of rations first/second party
summary(dt$P1P2rat)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.749   1.001   1.014   1.081   1.106   1.649    3658
```

``` r
#Gallagher Disproportionality measure:----
#(coded only for the elections that will remain in the final dataset)
sort(unique(dt$Es))
```

```
##  [1] "DEU_1961" "DEU_1965" "DEU_1976" "DEU_1980" "DEU_1983" "DEU_1987" "DEU_1990" "DEU_1994" "DEU_1998" "DEU_2009" "DEU_2013" "ESP_1979" "ESP_1982" "ESP_1993" "ESP_2004" "EST_2011" "FIN_2003" "FIN_2007" "FIN_2011" "GBR_2005" "GRC_1985" "GRC_1989" "GRC_1990" "GRC_1996" "GRC_2000" "GRC_2004" "GRC_2007" "GRC_2009" "GRC_2012" "HUN_1998" "HUN_2006" "IRL_2002" "IRL_2007" "IRL_2011" "ISL_1987" "ISL_1991" "ISL_1995" "ISL_1999" "ISL_2003" "ISL_2007" "ISL_2009" "ISL_2013" "ITA_2006" "ITA_2008" "LTU_2000" "NLD_1994" "NLD_1998" "NLD_2002" "NOR_1981" "NOR_1985" "NOR_1989" "NOR_1993" "NOR_1997" "NOR_2001" "NOR_2005" "PRT_2002" "PRT_2005" "PRT_2009" "SVN_2000" "SWE_1979" "SWE_1982" "SWE_1985" "SWE_1988" "SWE_1991" "SWE_1994" "SWE_1998" "SWE_2002" "SWE_2006" "SWE_2010"
```

``` r
dt$GDM=NA
dt$GDM[dt$Es=="DEU_1961"]=3.43#
dt$GDM[dt$Es=="DEU_1965"]=2.31#
dt$GDM[dt$Es=="DEU_1976"]=0.59#
dt$GDM[dt$Es=="DEU_1980"]=1.41#
dt$GDM[dt$Es=="DEU_1983"]=0.50#
dt$GDM[dt$Es=="DEU_1987"]=0.76#
dt$GDM[dt$Es=="DEU_1990"]=4.63#
dt$GDM[dt$Es=="DEU_1994"]=2.22#
dt$GDM[dt$Es=="DEU_1998"]=3.15#The figure in the effective number of legislative parties (Ns) column is based on 
dt$GDM[dt$Es=="DEU_2009"]=3.40#treating the CDU and CSU as separate parties.
dt$GDM[dt$Es=="DEU_2013"]=7.83#
dt$GDM[dt$Es=="ESP_1979"]=10.56
dt$GDM[dt$Es=="ESP_1982"]=8.02
dt$GDM[dt$Es=="ESP_1993"]=7.08
dt$GDM[dt$Es=="ESP_2004"]=4.25
dt$GDM[dt$Es=="FIN_2003"]=3.16
dt$GDM[dt$Es=="FIN_2007"]=3.20
dt$GDM[dt$Es=="FIN_2011"]=2.95
dt$GDM[dt$Es=="GBR_2005"]=16.73
dt$GDM[dt$Es=="GRC_1985"]=7.08
dt$GDM[dt$Es=="GRC_1989"]=3.94
dt$GDM[dt$Es=="GRC_1990"]=3.97
dt$GDM[dt$Es=="GRC_1996"]=9.45
dt$GDM[dt$Es=="GRC_2000"]=6.78
dt$GDM[dt$Es=="GRC_2004"]=7.37
dt$GDM[dt$Es=="GRC_2007"]=6.99
dt$GDM[dt$Es=="GRC_2009"]=7.29
dt$GDM[dt$Es=="GRC_2012"]=9.96#Jun
dt$GDM[dt$Es=="IRL_2002"]=6.62
dt$GDM[dt$Es=="IRL_2011"]=8.69
dt$GDM[dt$Es=="ISL_1987"]=2.31
dt$GDM[dt$Es=="ISL_1991"]=2.79
dt$GDM[dt$Es=="ISL_1995"]=1.98
dt$GDM[dt$Es=="ISL_1999"]=1.06
dt$GDM[dt$Es=="ISL_2003"]=1.85
dt$GDM[dt$Es=="ISL_2007"]=3.49
dt$GDM[dt$Es=="ISL_2009"]=2.58
dt$GDM[dt$Es=="ISL_2013"]=6.23
dt$GDM[dt$Es=="ITA_2006"]=3.61
dt$GDM[dt$Es=="ITA_2008"]=5.73
dt$GDM[dt$Es=="NLD_1994"]=1.08
dt$GDM[dt$Es=="NLD_1998"]=1.28
dt$GDM[dt$Es=="NLD_2002"]=0.88
dt$GDM[dt$Es=="NOR_1981"]=4.94
dt$GDM[dt$Es=="NOR_1985"]=4.75
dt$GDM[dt$Es=="NOR_1989"]=3.67
dt$GDM[dt$Es=="NOR_1993"]=3.95
dt$GDM[dt$Es=="NOR_1997"]=3.44
dt$GDM[dt$Es=="NOR_2005"]=2.67
dt$GDM[dt$Es=="PRT_2002"]=4.64
dt$GDM[dt$Es=="PRT_2005"]=5.75
dt$GDM[dt$Es=="PRT_2009"]=5.63
dt$GDM[dt$Es=="SWE_1979"]=1.27
dt$GDM[dt$Es=="SWE_1982"]=2.40
dt$GDM[dt$Es=="SWE_1985"]=1.35
dt$GDM[dt$Es=="SWE_1988"]=2.45
dt$GDM[dt$Es=="SWE_1991"]=2.86
dt$GDM[dt$Es=="SWE_1994"]=1.18
dt$GDM[dt$Es=="SWE_1998"]=0.97
dt$GDM[dt$Es=="SWE_2002"]=1.52
dt$GDM[dt$Es=="SWE_2006"]=3.02
dt$GDM[dt$Es=="SWE_2010"]=1.25


#CMPrile:----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="rile"]="CMPrile"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

#GRC_2012: there was an election one month before in May, need to exclude it from dCMP
# to merge in dt only the parties in the June election (which is the one coded by TEV):
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==201205),]
#same for GRC_1989: I excluded the June election because there are less than three parties coded,
# and need to exclude it from DCMP:
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==198906),]

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,168)]

#code pervote alternative i (CMPrile.i):
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.1"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.2"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.3"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.4"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.5"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPrile"]="CMPrile.6"
rm(dCMP)
# #check:
# #here the missing values cannot be replaced since there is not extra-CMP available rile


#CMPper415:----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="per415"]="CMPper415"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

#GRC_2012: there was an election one month before in May, need to exclude it from dCMP
# to merge in dt only the parties in the June election (which is the one coded by TEV):
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==201205),]
#same for GRC_1989: I excluded the June election because there are less than three parties coded,
# and need to exclude it from DCMP:
dCMP=dCMP[!(dCMP$Ec=="GRC"&dCMP$date==198906),]

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,59)]

#code pervote alternative i (CMPper415.i):
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.1"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.2"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.3"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.4"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.5"
dt=merge(dt, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(dt)[colnames(dt)=="CMPper415"]="CMPper415.6"
rm(dCMP)
# #check:
# #here the missing values cannot be replaced since there is not extra-CMP available rile


#Pi (party identification):----
# table(dt$RPID1)
# # 1 Does not identify with a political party
# # 2     Does identify with a political party
# table(dt$RPID4)
# # The direction of the party identification: which party? See Appendix 10 for party codes

dt$Pi=NA

dt$Pi[dt$Es=="ESP_1979"&dt$RPID4==1]=1
dt$Pi[dt$Es=="ESP_1979"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ESP_1979"&dt$RPID4==3]=3
dt$Pi[dt$Es=="ESP_1979"&dt$RPID4==4]=4

dt$Pi[dt$Es=="ESP_1982"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ESP_1982"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ESP_1982"&dt$RPID4==4]=3
dt$Pi[dt$Es=="ESP_1982"&dt$RPID4==1]=4
dt$Pi[dt$Es=="ESP_1982"&dt$RPID4==5]=5

dt$Pi[dt$Es=="ESP_1993"&dt$RPID4==1]=1
dt$Pi[dt$Es=="ESP_1993"&dt$RPID4==3]=2
dt$Pi[dt$Es=="ESP_1993"&dt$RPID4==4]=3
dt$Pi[dt$Es=="ESP_1993"&dt$RPID4==2]=4

dt$Pi[dt$Es=="ESP_2004"&dt$RPID4==1]=1
dt$Pi[dt$Es=="ESP_2004"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ESP_2004"&dt$RPID4==3]=3

dt$Pi[dt$Es=="EST_2011"&dt$RPID4==1]=1
dt$Pi[dt$Es=="EST_2011"&dt$RPID4==2]=2
dt$Pi[dt$Es=="EST_2011"&dt$RPID4==3]=3
dt$Pi[dt$Es=="EST_2011"&dt$RPID4==4]=4
dt$Pi[dt$Es=="EST_2011"&dt$RPID4==6]=5
dt$Pi[dt$Es=="EST_2011"&dt$RPID4==5]=6

dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==1]=1
dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==3]=2
dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==2]=3
dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==4]=4
dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==5]=5
dt$Pi[dt$Es=="FIN_2003"&dt$RPID4==6]=6

dt$Pi[dt$Es=="GBR_2005"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GBR_2005"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GBR_2005"&dt$RPID4==3]=3

dt$Pi[dt$Es=="GRC_1985"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_1985"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_1985"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_1985"&dt$RPID4==4]=4

dt$Pi[dt$Es=="GRC_1989"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_1989"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_1989"&dt$RPID4==3]=3

dt$Pi[dt$Es=="GRC_1990"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_1990"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_1990"&dt$RPID4==3]=3

dt$Pi[dt$Es=="GRC_1996"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_1996"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_1996"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_1996"&dt$RPID4==4]=4
dt$Pi[dt$Es=="GRC_1996"&dt$RPID4==5]=5

dt$Pi[dt$Es=="GRC_2000"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_2000"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_2000"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_2000"&dt$RPID4==4]=4

dt$Pi[dt$Es=="GRC_2004"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_2004"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_2004"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_2004"&dt$RPID4==4]=4

dt$Pi[dt$Es=="GRC_2007"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_2007"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_2007"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_2007"&dt$RPID4==4]=4
dt$Pi[dt$Es=="GRC_2007"&dt$RPID4==5]=5

dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==1]=1
dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==5]=2
dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==2]=3
dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==6]=4
dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==4]=5
dt$Pi[dt$Es=="HUN_1998"&dt$RPID4==3]=6

dt$Pi[dt$Es=="HUN_2006"&dt$RPID4==1]=1
dt$Pi[dt$Es=="HUN_2006"&dt$RPID4==2]=2
dt$Pi[dt$Es=="HUN_2006"&dt$RPID4==3]=3
dt$Pi[dt$Es=="HUN_2006"&dt$RPID4==4]=4

dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==1]=1
dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==2]=2
dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==4]=3
dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==5]=4
dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==3]=5
dt$Pi[dt$Es=="IRL_2002"&dt$RPID4==6]=6

dt$Pi[dt$Es=="ISL_1987"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_1987"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ISL_1987"&dt$RPID4==1]=3
dt$Pi[dt$Es=="ISL_1987"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ISL_1987"&dt$RPID4==5]=5

dt$Pi[dt$Es=="ISL_1991"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_1991"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ISL_1991"&dt$RPID4==1]=3
dt$Pi[dt$Es=="ISL_1991"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ISL_1991"&dt$RPID4==5]=5

dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==4]=3
dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==1]=4
dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==5]=5
dt$Pi[dt$Es=="ISL_1995"&dt$RPID4==6]=6

dt$Pi[dt$Es=="ISL_2003"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_2003"&dt$RPID4==1]=2
dt$Pi[dt$Es=="ISL_2003"&dt$RPID4==2]=3
dt$Pi[dt$Es=="ISL_2003"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ISL_2003"&dt$RPID4==5]=5

dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==3]=1#coalition==1
dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==5]=2
dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==6]=3
dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==1]=5
dt$Pi[dt$Es=="ITA_2006"&dt$RPID4==7]=6

dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==4]=1#coalition==1
dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==5]=3
dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==6]=4
dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==3]=5
dt$Pi[dt$Es=="ITA_2008"&dt$RPID4==1]=6

dt$Pi[dt$Es=="LTU_2000"&dt$RPID4==2]=1
dt$Pi[dt$Es=="LTU_2000"&dt$RPID4==3]=2
dt$Pi[dt$Es=="LTU_2000"&dt$RPID4==4]=3
dt$Pi[dt$Es=="LTU_2000"&dt$RPID4==1]=4

dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==6]=2
dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==3]=3
dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==1]=4
dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==5]=5
dt$Pi[dt$Es=="NLD_2002"&dt$RPID4==7]=6

dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==6]=2
dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==7]=3
dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==1]=4
dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==4]=5
dt$Pi[dt$Es=="NOR_2001"&dt$RPID4==5]=6

dt$Pi[dt$Es=="PRT_2005"&dt$RPID4==5]=1
dt$Pi[dt$Es=="PRT_2005"&dt$RPID4==4]=2
dt$Pi[dt$Es=="PRT_2005"&dt$RPID4==3]=3
dt$Pi[dt$Es=="PRT_2005"&dt$RPID4==2]=4
dt$Pi[dt$Es=="PRT_2005"&dt$RPID4==1]=5

dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==7]=3
dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==3]=4
dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==6]=5
dt$Pi[dt$Es=="SVN_2000"&dt$RPID4==1]=6

dt$Pi[dt$Es=="SWE_1979"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1979"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1979"&dt$RPID4==3]=3
dt$Pi[dt$Es=="SWE_1979"&dt$RPID4==4]=4
dt$Pi[dt$Es=="SWE_1979"&dt$RPID4==1]=5

dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==4]=3
dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==6]=4
dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==1]=5
dt$Pi[dt$Es=="SWE_2002"&dt$RPID4==3]=6

dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==7]=3
dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==4]=4
dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==3]=5
dt$Pi[dt$Es=="SWE_2010"&dt$RPID4==10]=6

#common elections TEV-CSES (minus exclusions, see "check common elections"):
dt$Pi[dt$Es=="DEU_1961"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1961"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1961"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1965"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1965"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1965"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1976"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1976"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1976"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1980"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1980"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1980"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1983"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1983"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1983"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1987"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1987"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1987"&dt$RPID4==3]=3

dt$Pi[dt$Es=="DEU_1990"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1990"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1990"&dt$RPID4==3]=3
dt$Pi[dt$Es=="DEU_1990"&dt$RPID4==5]=4

dt$Pi[dt$Es=="DEU_1994"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_1994"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_1994"&dt$RPID4==4]=3
dt$Pi[dt$Es=="DEU_1994"&dt$RPID4==3]=4
dt$Pi[dt$Es=="DEU_1994"&dt$RPID4==5]=5

dt$Pi[dt$Es=="DEU_1998"&dt$RPID4==1]=1
dt$Pi[dt$Es=="DEU_1998"&dt$RPID4==2]=2
dt$Pi[dt$Es=="DEU_1998"&dt$RPID4==4]=3
dt$Pi[dt$Es=="DEU_1998"&dt$RPID4==3]=4
dt$Pi[dt$Es=="DEU_1998"&dt$RPID4==5]=5

dt$Pi[dt$Es=="DEU_2009"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_2009"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_2009"&dt$RPID4==3]=3
dt$Pi[dt$Es=="DEU_2009"&dt$RPID4==5]=4
dt$Pi[dt$Es=="DEU_2009"&dt$RPID4==4]=5

dt$Pi[dt$Es=="DEU_2013"&dt$RPID4==2]=1
dt$Pi[dt$Es=="DEU_2013"&dt$RPID4==1]=2
dt$Pi[dt$Es=="DEU_2013"&dt$RPID4==5]=3
dt$Pi[dt$Es=="DEU_2013"&dt$RPID4==4]=4
dt$Pi[dt$Es=="DEU_2013"&dt$RPID4==3]=5

dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==1]=1
dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==3]=2
dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==2]=3
dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==4]=4
dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==5]=5
dt$Pi[dt$Es=="FIN_2007"&dt$RPID4==7]=6

dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==3]=1
dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==2]=2
dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==8]=3
dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==1]=4
dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==4]=5
dt$Pi[dt$Es=="FIN_2011"&dt$RPID4==5]=6

dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==4]=4
dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==5]=5
dt$Pi[dt$Es=="GRC_2009"&dt$RPID4==6]=6

dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==1]=1
dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==2]=2
dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==3]=3
dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==4]=4
dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==5]=5
dt$Pi[dt$Es=="GRC_2012"&dt$RPID4==6]=6

dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==1]=1
dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==2]=2
dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==4]=3
dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==3]=4
dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==6]=5
dt$Pi[dt$Es=="IRL_2007"&dt$RPID4==5]=6

dt$Pi[dt$Es=="IRL_2011"&dt$RPID4==2]=1
dt$Pi[dt$Es=="IRL_2011"&dt$RPID4==3]=2
dt$Pi[dt$Es=="IRL_2011"&dt$RPID4==1]=3
dt$Pi[dt$Es=="IRL_2011"&dt$RPID4==4]=4
dt$Pi[dt$Es=="IRL_2011"&dt$RPID4==5]=5#

dt$Pi[dt$Es=="ISL_1999"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_1999"&dt$RPID4==1]=2
dt$Pi[dt$Es=="ISL_1999"&dt$RPID4==2]=3
dt$Pi[dt$Es=="ISL_1999"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ISL_1999"&dt$RPID4==5]=5

dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==1]=2
dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==4]=3
dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==2]=4
dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==5]=5
dt$Pi[dt$Es=="ISL_2007"&dt$RPID4==6]=6#

dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==1]=1
dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==3]=2
dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==4]=3
dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==2]=4
dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==5]=5#
dt$Pi[dt$Es=="ISL_2009"&dt$RPID4==6]=6#

dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==3]=1
dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==2]=2
dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==1]=3
dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==4]=4
dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==5]=5
dt$Pi[dt$Es=="ISL_2013"&dt$RPID4==6]=6

dt$Pi[dt$Es=="NLD_1994"&dt$RPID4==1]=1
dt$Pi[dt$Es=="NLD_1994"&dt$RPID4==2]=2
dt$Pi[dt$Es=="NLD_1994"&dt$RPID4==3]=3
dt$Pi[dt$Es=="NLD_1994"&dt$RPID4==4]=4

dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==1]=1#EV 4 parties, CSES 6 parties coded
dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==3]=2
dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==2]=3
dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==4]=4
dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==5]=5
dt$Pi[dt$Es=="NLD_1998"&dt$RPID4==7]=6#

dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==6]=2
dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==4]=3
dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==5]=4
dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==1]=5
dt$Pi[dt$Es=="NOR_1981"&dt$RPID4==7]=6

dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==6]=2
dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==4]=3
dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==5]=4
dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==1]=5
dt$Pi[dt$Es=="NOR_1985"&dt$RPID4==7]=6

dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==6]=2
dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==7]=3
dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==1]=4
dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==4]=5
dt$Pi[dt$Es=="NOR_1989"&dt$RPID4==5]=6

dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==5]=2
dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==6]=3
dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==1]=4
dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==4]=5
dt$Pi[dt$Es=="NOR_1993"&dt$RPID4==7]=6

dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==7]=2
dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==4]=3
dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==6]=4
dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==5]=5
dt$Pi[dt$Es=="NOR_1997"&dt$RPID4==1]=6

dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==2]=1
dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==7]=2
dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==6]=3
dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==1]=4
dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==4]=5
dt$Pi[dt$Es=="NOR_2005"&dt$RPID4==5]=6

dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==4]=1
dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==5]=2
dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==2]=3
dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==3]=4
dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==1]=5
dt$Pi[dt$Es=="PRT_2002"&dt$RPID4==6]=6

dt$Pi[dt$Es=="PRT_2009"&dt$RPID4==5]=1#osym4-5  inverted!?
dt$Pi[dt$Es=="PRT_2009"&dt$RPID4==4]=2
dt$Pi[dt$Es=="PRT_2009"&dt$RPID4==2]=3
dt$Pi[dt$Es=="PRT_2009"&dt$RPID4==1]=4
dt$Pi[dt$Es=="PRT_2009"&dt$RPID4==3]=5

dt$Pi[dt$Es=="SWE_1982"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1982"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1982"&dt$RPID4==3]=3
dt$Pi[dt$Es=="SWE_1982"&dt$RPID4==4]=4
dt$Pi[dt$Es=="SWE_1982"&dt$RPID4==1]=5

dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==4]=3
dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==3]=4
dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==1]=5
dt$Pi[dt$Es=="SWE_1985"&dt$RPID4==6]=6

dt$Pi[dt$Es=="SWE_1988"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1988"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1988"&dt$RPID4==4]=3
dt$Pi[dt$Es=="SWE_1988"&dt$RPID4==3]=4
dt$Pi[dt$Es=="SWE_1988"&dt$RPID4==1]=5

dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==4]=3
dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==3]=4
dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==6]=5
dt$Pi[dt$Es=="SWE_1991"&dt$RPID4==9]=6

dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==3]=3
dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==4]=4
dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==1]=5
dt$Pi[dt$Es=="SWE_1994"&dt$RPID4==7]=6

dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==1]=3
dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==6]=4
dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==3]=5
dt$Pi[dt$Es=="SWE_1998"&dt$RPID4==4]=6

dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==2]=1
dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==5]=2
dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==3]=3
dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==4]=4
dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==6]=5
dt$Pi[dt$Es=="SWE_2006"&dt$RPID4==1]=6

dt$Pi[dt$RPID1!=2]=NA#if R does not identify with any party


#EeconS (economy subjective retrospective sociotropic):----

colnames(dt)[colnames(dt)=="RRSEE"]="EeconS"
dt$EeconS[dt$EeconS>1]=NA
dt$EeconS=as.numeric(dt$EeconS)

# 0. Negative evaluation
# 1. Positive evaluation

# #TEV recoded CSES EeconS from c(1,2,3,4,5) to c(1, 0.75, 0.5, 0.25, 0):
# dt_=dt[dt$Es=="DEU_2013",]
# dt_$EeconS[1:20]
# table(dt_$EeconS)
# rm(dt_)


#PrePost:----
colnames(dt)[colnames(dt)=="PREPOST"]="PrePost"
dt$PrePost=as.numeric(dt$PrePost)

# 1. Post-election study
# 2. Pre-election study
# 3. Panel, with some pre-election and some post-election data

# table(d$Es,dt$Ed)# code prepost only for EV in de dataset
#           CSES EV-LP   TEV
# AUS_1993     0 18138     0#post#
# CAN_1968     0 16602     0#post#
# CAN_1974     0 15372     0#post#
# CAN_1979     0 16482     0#post#
# CAN_1988     0 17538     0#panel#
# CAN_1993     0 20040     0#panel#
# DNK_1971     0  7812     0#NA#
# DNK_1973     0  3198     0#NA#
# DNK_1994     0 12126     0#NA#
# GBR_1974     0 28962     0#post#
# GBR_1979     0 11358     0#post#
# NLD_1986     0  9780     0#panel#


#Media use:----

dt$Mnwsp=dt$RMEDUS1#newspaper use
dt$Mtele=dt$RMEDUS2#television use
dt$Mradi=dt$RMEDUS3#radio use
dt$Minte=dt$RMEDUS4#internet use

dt$Mnwsp[dt$Mnwsp>1]=NA
dt$Mtele[dt$Mtele>1]=NA
dt$Mradi[dt$Mradi>1]=NA
dt$Minte[dt$Minte>1]=NA

  
#fix IRL_2007:----

#read dtI (TEV), ddI (CSES), and di (NES) for IRL_2007:
dtI=dt[dt$Es=="IRL_2007",]
ddI=dew[dew$Es=="IRL_2007",]
di=read.dta("INESWide_Beta.dta")
```

```
## Warning in read.dta("INESWide_Beta.dta"): value labels ('House') for 'v0758_07' are missing
```

```
## Warning in read.dta("INESWide_Beta.dta"): value labels ('e41cos') for 'v0979a_07' are missing
```

``` r
#Va corresponds in aggregate but not in the order:
table(dtI$Va)
```

```
## 
##   1   2   3   4   5   6 
## 492 320 130  49  55  41
```

``` r
table(ddI$Va)
```

```
## 
##   1   2   3   4   5   6 
## 492 320 130  49  55  41
```

``` r
summary(dtI$Va-ddI$Va)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## -5.0000 -1.0000  0.0000  0.0024  1.0000  5.0000     606
```

``` r
#order the datasets by their IDs:
ddI=ddI[order(ddI$Rid),]
dtI=dtI[order(dtI$ORESPID),]
di=di[order(di$id),]

#even after ordering by IDS, Va does not correspond in the order:
summary(dtI$Va-ddI$Va)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## -5.0000 -1.0000  0.0000 -0.0061  1.0000  5.0000     614
```

``` r
#IDs do not correspond between datasets :
length(sort(unique(dtI$ORESPID)))
```

```
## [1] 1435
```

``` r
sort(unique(dtI$ORESPID))[1:20]
```

```
## <labelled<character>[20]>: OV - RESPONDENTS ORIGINAL NUMBERING
##  [1]       1.00       2.00       3.00       4.00       5.00       6.00       7.00       8.00       9.00      10.00      11.00      12.00      13.00      14.00      15.00      16.00      17.00      18.00      19.00      20.00
## 
## Labels:
##       value   label
##  9999999999 Missing
```

``` r
dtI$RRESPID=as.character(dtI$RRESPID)
sort(unique(dtI$RRESPID))[1:20]
```

```
##  [1] "1420071000001" "1420071000002" "1420071000003" "1420071000004" "1420071000005" "1420071000006" "1420071000007" "1420071000008" "1420071000009" "1420071000010" "1420071000011" "1420071000012" "1420071000013" "1420071000014" "1420071000015" "1420071000016" "1420071000017" "1420071000018" "1420071000019" "1420071000020"
```

``` r
length(sort(unique(ddI$Rid)))
```

```
## [1] 1435
```

``` r
sort(unique(ddI$Rid))[1:20]
```

```
##  [1] "372020070010010200" "372020070010010400" "372020070010010500" "372020070010010700" "372020070010010900" "372020070010011000" "372020070010011100" "372020070010011600" "372020070010020100" "372020070010020400" "372020070010020500" "372020070010020800" "372020070010021000" "372020070010021100" "372020070010021200" "372020070010021300" "372020070010021400" "372020070010021500" "372020070010040300" "372020070010040500"
```

``` r
length(sort(unique(di$id)))
```

```
## [1] 2946
```

``` r
sort(unique(di$id))[1:20]
```

```
##  [1]  102  105  205  412  506  602  603  606  608  609  610  612  615  811  816  910 1120 1414 1422 1423
```

``` r
#CSES and TEV have same aggregate Pl.i:
table(ddI$Pl.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 135  37  63  74  71 191 100 139 182 113 282
```

``` r
table(dtI$Pl.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 135  37  63  74  71 191 100 139 182 113 282
```

``` r
table(ddI$Pl.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  90  51  72  70 116 293 178 150 135  77 134
```

``` r
table(dtI$Pl.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  90  51  72  70 116 293 178 150 135  77 134
```

``` r
table(ddI$Pl.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  91  46  82 115 135 297 168 146 111  63  78
```

``` r
table(dtI$Pl.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  91  46  82 115 135 297 168 146 111  63  78
```

``` r
table(ddI$Pl.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 103  46  85  98 132 311 168 145 119  57  52
```

``` r
table(dtI$Pl.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 103  46  85  98 132 311 168 145 119  57  52
```

``` r
table(ddI$Pl.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 453 158 141  97  89 134  54  41  50  32  53
```

``` r
table(dtI$Pl.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 453 158 141  97  89 134  54  41  50  32  53
```

``` r
table(ddI$Pl.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 209 111 154 127 157 197 114  84  67  42  31
```

``` r
table(dtI$Pl.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 209 111 154 127 157 197 114  84  67  42  31
```

``` r
#CSES and TEV have same aggregate Ll.i BUT for Ll.1:
table(ddI$Ll.1)#Fianna Fail (FF) - Bertie Ahern (FF) [CSES imdb]
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 133  33  61  56  58 172  96 149 205 153 281
```

``` r
table(dtI$Ll.1)#Fiánna Fail (FF) / Bertie Ahern
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 102  67  82  82 138 242 192 169 154  54  85
```

``` r
table(ddI$Ll.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 102  67  82  82 138 242 192 169 154  54  85
```

``` r
table(dtI$Ll.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 102  67  82  82 138 242 192 169 154  54  85
```

``` r
table(ddI$Ll.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  94  51  89 108 137 249 164 154 133  58  69
```

``` r
table(dtI$Ll.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  94  51  89 108 137 249 164 154 133  58  69
```

``` r
table(ddI$Ll.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  95  43  90 119 144 301 138 124  90  37  39
```

``` r
table(dtI$Ll.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  95  43  90 119 144 301 138 124  90  37  39
```

``` r
table(ddI$Ll.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 366 143 158 101  86 177  68  86  47  35  53
```

``` r
table(dtI$Ll.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 366 143 158 101  86 177  68  86  47  35  53
```

``` r
table(ddI$Ll.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 262 121 140 124 133 188  80  75  71  35  42
```

``` r
table(dtI$Ll.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 262 121 140 124 133 188  80  75  71  35  42
```

``` r
#the NES for Ll.1 is the same than CSES:
table(di$v0521_07)
```

```
## 
## strongly dislike               _1               _2               _3               _4               _5               _6               _7               _8               _9    strongly like        dont know         dontknow 
##              134               33               61               57               58              172               96              149              206              153              282               15                0
```

``` r
#By putting together all the variables with same aggregate values between CSES and TEV it is
# not possible to uniquely identify respondents also adding,LRR,RREGION,RAGE,RGENDER
# (not possible to add Rage as it is not the same cumulatively):
table(dtI$Rage)
```

```
## 
## 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 94 
##  1  2  2  2  4  7 24 25 19 20 19 22 16 19 18 20 22 18 29 24 24 28 23 35 24 34 42 30 27 29 19 22 25 27 20 32 28 36 37 29 34 39 39 24 36 33 18 24 23 23 16 18 15 13 16 12 19 18 18  7  6 18  7  9  2  9  5  2  4  4  2  2  1  2
```

``` r
table(ddI$Rage)
```

```
## 
## 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 93 
##  3  3  3  3 27 23 20 20 21 23 15 17 15 18 23 20 29 22 25 26 25 29 27 30 40 37 24 32 19 22 22 30 22 30 31 31 39 28 33 40 36 29 30 40 18 23 27 17 19 19 15 14 16 11 21 17 16 13  5 14 13  5  6  6  6  4  3  3  4  1  1  1  2
```

``` r
dtI$match=paste0(dtI$RREGION,"_",dtI$RGENDER,"_",dtI$Va,"_",dtI$LRR,"_",dtI$Pl.1,"_",dtI$Pl.2,"_",dtI$Pl.3,"_",dtI$Pl.4,"_",dtI$Pl.5,"_",dtI$Pl.6
                 ,dtI$Ll.2,"_",dtI$Ll.3,"_",dtI$Ll.4,"_",dtI$Ll.5,"_",dtI$Ll.6)
length(sort(unique(dtI$match)))
```

```
## [1] 1432
```

``` r
nrow(dtI)
```

```
## [1] 1435
```

``` r
#therefore I keep only the data in the CSES for IRL_2007, which at the end only causes to
# loose the data regarding media use:
dt=dt[!(dt$Es %in% c("IRL_2007")),]#exclude IRL_2007 from TEV

rm(dtI,ddI,di)#removing working variables


#fix NOR_2001:----

#read dtN (TEV) and ddN (NES) for NOR_2001:
dtN=dt[dt$Es=="NOR_2001",]
ddN=read.dta("NSD0663.dta")

#order the datasets by their IDs:
ddN=ddN[order(ddN$v001),]
dtN=dtN[order(dtN$ORESPID),]

#Va:v380
sort(table(ddN$v380))#vote choice:
```

```
## 
##  20  99   1  98  10   4   6   9   5   2   3   8 
##   4   5  25  36  38  76  98 187 226 254 381 463
```

``` r
class(ddN$v380)
```

```
## [1] "integer"
```

``` r
# 3 Labour party (DnA)
# 8 Conservative Party (H)
# 9 Progress Party (FrP)
# 2 Socialist Left Party (SV)
# 5 Christian Democratic Party (KrF)
# 6 Center Party (Sp)
ddN$Va=NA
ddN$Va[ddN$v380==3]=1
ddN$Va[ddN$v380==8]=2
ddN$Va[ddN$v380==9]=3
ddN$Va[ddN$v380==2]=4
ddN$Va[ddN$v380==5]=5
ddN$Va[ddN$v380==6]=6
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==2]=1#code Va for dtN:
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==6]=2
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==7]=3
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==1]=4
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==4]=5
# dtN$Va[dtN$Es=="NOR_2001"&dtN$Vn==5]=6
summary(dtN$Va-ddN$Va)#vote choice is the same between TEV and Norway: it corresponds Id by Id!!!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       0     842
```

``` r
#Rage:
ddN$Rage=ddN$v003
ddN$Rage[ddN$Rage==17]=18#Norway NES coded age also 17 while TEV puts it in 18
summary(dtN$Rage-ddN$Rage)#also it corresponds ID by ID!!!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0       0       0       0       0       0
```

``` r
#LRR:
ddN$LRR=ddN$v316
ddN$LRR=as.numeric(ddN$LRR)#rescaling 0-10 scale
ddN$LRR=ddN$LRR-1
ddN$LRR[ddN$LRR>10]=NA
summary(dtN$LRR-ddN$LRR)#also it corresponds ID by ID!!!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       0     392
```

``` r
#Media use:
#there is no data on Media use: summary(dtN$RMEDUS4)

#EeconS: (it is pre-election in the dataset)
#v095:
# 1 better
# 2 same
# 3 worse
#v096:
# 1 much better
# 2 a bit better
#v097:
# 1 much worse
# 2 a bit worse
ddN$v095=as.numeric(ddN$v095)#recode 1:5 scale CSES: 1. GOTTEN BETTER; 5. GOTTEN WORSE
ddN$v096=as.numeric(ddN$v096)
ddN$v097=as.numeric(ddN$v097)
ddN$v095[ddN$v095>5]=NA#coding missing as NAs
ddN$v096[ddN$v096>2]=NA#coding missing as NAs
ddN$v097[ddN$v097>2]=NA#coding missing as NAs
ddN$v097[ddN$v097==2]=4
ddN$v097[ddN$v097==1]=5
ddN$EeconS=NA
ddN$EeconS=ifelse(ddN$v095<3, ddN$v096,
                  (ifelse(ddN$v095==3, 3,
                          (ifelse(ddN$v095>3,ddN$v097,ddN$EeconS)))))
ddN$EeconS[ddN$EeconS==1]=1#recode to 0-1 scale TEV: 0. Negative evaluation; 1. Positive evaluation
ddN$EeconS[ddN$EeconS==2]=0.75
ddN$EeconS[ddN$EeconS==3]=0.5
ddN$EeconS[ddN$EeconS==4]=0.25
ddN$EeconS[ddN$EeconS==5]=0
# colnames(dtN)[colnames(dtN)=="RRSEE"]="EeconS"
# dtN$EeconS[dtN$EeconS>1]=NA
# dtN$EeconS=as.numeric(dtN$EeconS)
summary(dtN$EeconS-dtN$EeconS)#also it corresponds ID by ID!!!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       0     204
```

``` r
#however:
#Pl is out:
ddN$Pl.1=ddN$v300#Pl Labour Party
ddN$Pl.2=ddN$v299#Pl Conservative Party
ddN$Pl.3=ddN$v301#Pl Progress Party
ddN$Pl.4=ddN$v298#Pl Socialist Left
ddN$Pl.5=ddN$v295#Pl Christian Dem
ddN$Pl.6=ddN$v297#Pl Center Party
# Pl 0.49624   1.64253  0.01863   0.01816 27.321 <2e-16
# Ll 0.15829   1.17151  0.01837   0.01812  8.735 <2e-16
ddN$Pl.1=as.numeric(ddN$Pl.1)#rescaling 0-10 scale
ddN$Pl.2=as.numeric(ddN$Pl.2)
ddN$Pl.3=as.numeric(ddN$Pl.3)
ddN$Pl.4=as.numeric(ddN$Pl.4)
ddN$Pl.5=as.numeric(ddN$Pl.5)
ddN$Pl.6=as.numeric(ddN$Pl.6)
ddN$Pl.1=ddN$Pl.1-1
ddN$Pl.2=ddN$Pl.2-1
ddN$Pl.3=ddN$Pl.3-1
ddN$Pl.4=ddN$Pl.4-1
ddN$Pl.5=ddN$Pl.5-1
ddN$Pl.6=ddN$Pl.6-1
ddN$Pl.1[ddN$Pl.1>10]=NA
ddN$Pl.2[ddN$Pl.2>10]=NA
ddN$Pl.3[ddN$Pl.3>10]=NA
ddN$Pl.4[ddN$Pl.4>10]=NA
ddN$Pl.5[ddN$Pl.5>10]=NA
ddN$Pl.6[ddN$Pl.6>10]=NA

#Ll is out:
ddN$Ll.1=ddN$v322#Ll Jens Stoltenberg Labour Party
ddN$Ll.2=ddN$v321#Ll Jan Petersen Conservative Party
ddN$Ll.3=ddN$v323#Ll Carl I. Hagen Progress Party
ddN$Ll.4=ddN$v320#Ll Kristin Halvorsen Socialist Left
ddN$Ll.5=ddN$v317#Ll Valgerd Svarstad Haugland Christian Dem
ddN$Ll.6=ddN$v319#Ll Odd Roger Enoksen Center Party
# ddN$v086#Ll Thorbjørn Jagland
# ddN$v078#Ll Lars Sponheim
# ddN$v084#Ll Aslak Sira Myhre
# ddN$v085#Ll Kjell Magne Bondevik
ddN$Ll.1=as.numeric(ddN$Ll.1)#rescaling 0-10 scale
ddN$Ll.2=as.numeric(ddN$Ll.2)
ddN$Ll.3=as.numeric(ddN$Ll.3)
ddN$Ll.4=as.numeric(ddN$Ll.4)
ddN$Ll.5=as.numeric(ddN$Ll.5)
ddN$Ll.6=as.numeric(ddN$Ll.6)
ddN$Ll.1=ddN$Ll.1-1
ddN$Ll.2=ddN$Ll.2-1
ddN$Ll.3=ddN$Ll.3-1
ddN$Ll.4=ddN$Ll.4-1
ddN$Ll.5=ddN$Ll.5-1
ddN$Ll.6=ddN$Ll.6-1
ddN$Ll.1[ddN$Ll.1>10]=NA
ddN$Ll.2[ddN$Ll.2>10]=NA
ddN$Ll.3[ddN$Ll.3>10]=NA
ddN$Ll.4[ddN$Ll.4>10]=NA
ddN$Ll.5[ddN$Ll.5>10]=NA
ddN$Ll.6[ddN$Ll.6>10]=NA

#Pl and Ll are completely out:
table(dtN$Pl.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  54  66 141 221 267 349 254 279 227  92  57
```

``` r
table(ddN$Pl.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  75  36  92 211 284 463 253 241 215  78  61
```

``` r
table(dtN$Pl.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  34  36 108 198 240 378 265 258 297 118  77
```

``` r
table(ddN$Pl.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  34  36 108 198 240 378 265 258 297 118  77
```

``` r
table(dtN$Pl.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  97  89 202 305 377 461 215 134  78  28  12
```

``` r
table(ddN$Pl.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 269 192 254 227 206 250 162 167 149  72  61
```

``` r
table(dtN$Pl.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 269 192 254 227 206 250 162 167 149  72  61
```

``` r
table(ddN$Pl.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  54  66 141 221 267 349 254 279 227  92  57
```

``` r
table(dtN$Pl.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  75  36  92 211 284 463 253 241 215  78  61
```

``` r
table(ddN$Pl.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  64  60 122 207 258 404 298 270 194  69  64
```

``` r
table(dtN$Pl.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  64  60 122 207 258 404 298 270 194  69  64
```

``` r
table(ddN$Pl.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 101 110 211 340 416 408 177 118  78  24  15
```

``` r
table(dtN$Ll.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 101 110 191 313 415 396 186 160  88  22  14
```

``` r
table(ddN$Ll.1)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  55  35  80 153 239 401 335 321 238  92  50
```

``` r
table(dtN$Ll.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  21  34  90 155 287 404 312 315 243  79  47
```

``` r
table(ddN$Ll.2)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  21  34  90 155 287 404 312 315 243  79  47
```

``` r
table(dtN$Ll.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 212 126 204 210 194 260 198 206 210  88  92
```

``` r
table(ddN$Ll.3)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 212 126 204 210 194 260 198 206 210  88  92
```

``` r
table(dtN$Ll.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  24  26  49  80 176 271 313 366 374 181 134
```

``` r
table(ddN$Ll.4)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  24  26  49  80 176 271 313 366 374 181 134
```

``` r
table(dtN$Ll.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  45  48  79 130 198 358 306 303 289 149  97
```

``` r
table(ddN$Ll.5)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
## 193 162 231 304 360 325 175 133  68  17  19
```

``` r
table(dtN$Ll.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  53  92 225 356 430 370 188  92  38   9  12
```

``` r
table(ddN$Ll.6)
```

```
## 
##   0   1   2   3   4   5   6   7   8   9  10 
##  53  92 225 356 430 370 188  92  38   9  12
```

``` r
#LRP.i is also out:
ddN$LRP.1=ddN$v308#Pl Labour Party
ddN$LRP.2=ddN$v307#Pl Conservative Party
ddN$LRP.3=ddN$v309#Pl Progress Party
ddN$LRP.4=ddN$v306#Pl Socialist Left
ddN$LRP.5=ddN$v303#Pl Christian Dem
ddN$LRP.6=ddN$v305#Pl Center Party
ddN$LRP.1=as.numeric(ddN$LRP.1)#rescaling 0-10 scale
ddN$LRP.2=as.numeric(ddN$LRP.2)
ddN$LRP.3=as.numeric(ddN$LRP.3)
ddN$LRP.4=as.numeric(ddN$LRP.4)
ddN$LRP.5=as.numeric(ddN$LRP.5)
ddN$LRP.6=as.numeric(ddN$LRP.6)
ddN$LRP.1=ddN$LRP.1-1
ddN$LRP.2=ddN$LRP.2-1
ddN$LRP.3=ddN$LRP.3-1
ddN$LRP.4=ddN$LRP.4-1
ddN$LRP.5=ddN$LRP.5-1
ddN$LRP.6=ddN$LRP.6-1
ddN$LRP.1[ddN$LRP.1>10]=NA
ddN$LRP.2[ddN$LRP.2>10]=NA
ddN$LRP.3[ddN$LRP.3>10]=NA
ddN$LRP.4[ddN$LRP.4>10]=NA
ddN$LRP.5[ddN$LRP.5>10]=NA
ddN$LRP.6[ddN$LRP.6>10]=NA
summary(dtN$LRP.1-ddN$LRP.1)#it does not correspond ID by ID!!!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## -10.000  -3.000  -2.000  -1.807  -1.000  10.000     441
```

``` r
#therefore I need to correct Pl.i, Ll.i, and LRP.i:
# I can just copy them since I ordered by ID and all the other variables are the same ID by ID
# and before I  just need to order dt by Es and ID:
dt=dt[order(dt$Es,dt$ORESPID),]
summary(dt$Va[dt$Es=="NOR_2001"]-ddN$Va)#check the order is correct!
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       0     842
```

``` r
dt$Pl.1[dt$Es=="NOR_2001"]=ddN$Pl.1#assign correct values:
dt$Pl.2[dt$Es=="NOR_2001"]=ddN$Pl.2
dt$Pl.3[dt$Es=="NOR_2001"]=ddN$Pl.3
dt$Pl.4[dt$Es=="NOR_2001"]=ddN$Pl.4
dt$Pl.5[dt$Es=="NOR_2001"]=ddN$Pl.5
dt$Pl.6[dt$Es=="NOR_2001"]=ddN$Pl.6
dt$Ll.1[dt$Es=="NOR_2001"]=ddN$Ll.1
dt$Ll.2[dt$Es=="NOR_2001"]=ddN$Ll.2
dt$Ll.3[dt$Es=="NOR_2001"]=ddN$Ll.3
dt$Ll.4[dt$Es=="NOR_2001"]=ddN$Ll.4
dt$Ll.5[dt$Es=="NOR_2001"]=ddN$Ll.5
dt$Ll.6[dt$Es=="NOR_2001"]=ddN$Ll.6
dt$LRP.1[dt$Es=="NOR_2001"]=ddN$LRP.1
dt$LRP.2[dt$Es=="NOR_2001"]=ddN$LRP.2
dt$LRP.3[dt$Es=="NOR_2001"]=ddN$LRP.3
dt$LRP.4[dt$Es=="NOR_2001"]=ddN$LRP.4
dt$LRP.5[dt$Es=="NOR_2001"]=ddN$LRP.5
dt$LRP.6[dt$Es=="NOR_2001"]=ddN$LRP.6

rm(dtN,ddN)#removing working variables


#dataset common elections:----

#keep only common elections between CSES and TEV:
dt_=dt[(dt$Es %in% c(sort(unique(dew$Es)))),]#common elections
dew_=dew[(dew$Es %in% c(sort(unique(dt$Es)))),]#common elections

#keep only variables of interest:
dt_=dt_[,names(dt_) %in% c("Ec","Ey","Es","NP","Rwd","Vt","Va","Pl.1","Pl.2","Pl.3","Pl.4","Pl.5","Pl.6"
                           ,"Ll.1","Ll.2","Ll.3","Ll.4","Ll.5","Ll.6"
                           ,"LRR","LRP.1","LRP.2","LRP.3","LRP.4","LRP.5","LRP.6")]
dew_=dew_[,names(dew_) %in% c("Ec","Ey","Es","NP","Rwd","Vt","Va","Pl.1","Pl.2","Pl.3","Pl.4","Pl.5","Pl.6"
                              ,"Ll.1","Ll.2","Ll.3","Ll.4","Ll.5","Ll.6"
                              ,"LRR","LRP.1","LRP.2","LRP.3","LRP.4","LRP.5","LRP.6")]

#add dataset dummy:
dt_$Ed=0#TEV (analyzed elections)
dew_$Ed=1#CSES-EV-LP (non-analyzed elections)

#stack:
dd=rbind(dt_,dew_)

#create long datasets and add relevant variables:
dd=as.data.frame(dd)
dd=mlogit.data(dd, varying=c(7:24), choice="Va", shape="wide")#create long dtt
dd$LRD=abs(dd$LRR-dd$LRP)#Left-Right Distance voter-party
dd$time=dd$Ey-1960
dd$Esalt=paste0(dd$Es,dd$alt)

#save:
save(dd, file = "d29_doubleEs.RData")


#main dataset:----

#keep in CSES-EV-LP only elections not already present in TEV:
dew=dew[!(dew$Es %in% c(sort(unique(dt$Es)))),]

# #keep in TEV only elections not already present in CSES-EV-LP:
# dt=dt[!(dt$Es %in% c(sort(unique(dew$Es)))),]

#keep only variables of interest:
dt=dt[,names(dt) %in% c(names(dew),"Mnwsp","Mtele","Mradi","Minte")]

#code Ed election dataset:
dt$Ed="TEV"
# dew$Ed[dew$Ey<1996]="EV-LP"
# dew$Ed[dew$Ey>=1996]="CSES"

#code NAs for media use in dew:
dew$Mnwsp=NA
dew$Mradi=NA
dew$Mtele=NA
dew$Minte=NA

#remove non relevant columns dew:
# dew=dew[, !names(dew) %in% c("Rid","CMPid.1","CMPid.2","CMPid.3","CMPid.4","CMPid.5","CMPid.6")]
dew=dew[, !names(dew) %in% c("Rid")]

names(dew)
```

```
##  [1] "Ec"          "Ey"          "Es"          "Ed"          "Rwd"         "Rage"        "NP"          "CoalCode"    "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"        "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"        "Ll.6"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"       "LRP.6"       "EeconS"      "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"        "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Ps.1"        "Ps.2"        "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CMPid.1"     "CMPid.2"     "CMPid.3"     "CMPid.4"     "CMPid.5"     "CMPid.6"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "CMPper415.4" "CMPper415.5" "CMPper415.6" "Pi"          "Mnwsp"       "Mradi"       "Mtele"       "Minte"
```

``` r
names(dt)
```

```
##  [1] "Ec"          "Ey"          "CMPid.6"     "CMPid.5"     "CMPid.4"     "CMPid.3"     "CMPid.2"     "CMPid.1"     "PrePost"     "Rage"        "LRR"         "EeconS"      "Vt"          "Es"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"        "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"        "Ll.6"        "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"       "LRP.6"       "NP"          "CoalCode"    "Rwd"         "VPf"         "Pv.1"        "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Ps.1"        "Ps.2"        "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "P1P2rat"     "GDM"         "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CMPper415.1" "CMPper415.2" "CMPper415.3" "CMPper415.4" "CMPper415.5" "CMPper415.6" "Pi"          "Mnwsp"       "Mtele"       "Mradi"       "Minte"       "Ed"
```

``` r
#reorder dt columns:
dt=dt[,c(names(dew))]

#merge dew and dt:
de=rbind(dew,dt)

#exclude data that will not enter in the analysis to limit memory use:
de=de[!is.na(de$Va),]#remove respondents without vote choice
Pl=de[, names(de) %in% c(paste0("Pl.", 1:6))]#keep only respondents (and elections) with coded Pl,Ll (for at least one party)
Pl=as.matrix(Pl)
de=de[rowMins(Pl, na.rm=T)<20,]
Ll=de[, names(de) %in% c(paste0("Ll.", 1:6))]
Ll=as.matrix(Ll)
de=de[rowMins(Ll, na.rm=T)<20,]
rm(Pl,Ll)
de_temp=de[!duplicated(de$Es),]#remove countries with only one election coded (they will not generate any time trend)
names(which(table(de_temp$Ec)==1))#"ARG" "BGR" "EST" "HRV" "LTU" "MNE" "SRB" "TWN"
```

```
## [1] "ARG" "BGR" "EST" "HRV" "LTU" "MNE" "SRB" "TWN"
```

``` r
de=de[!(de$Ec %in% c(names(which(table(de_temp$Ec)==1)))),]
rm(de_temp)

#subset without Eastern Europe:
de=de[!(de$Ec %in% c("CZE","HUN","LVA","POL","SVK","SVN","ZAF")),]#exclude non democracies before 1992 (mainly Eastern Europe)

de3=de#temp dataset for only top three parties

names(de)
```

```
##  [1] "Ec"          "Ey"          "Es"          "Ed"          "Rwd"         "Rage"        "NP"          "CoalCode"    "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"        "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"        "Ll.6"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"       "LRP.6"       "EeconS"      "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"        "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Ps.1"        "Ps.2"        "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CMPid.1"     "CMPid.2"     "CMPid.3"     "CMPid.4"     "CMPid.5"     "CMPid.6"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "CMPper415.4" "CMPper415.5" "CMPper415.6" "Pi"          "Mnwsp"       "Mradi"       "Mtele"       "Minte"
```

``` r
# [1] "Ec"          "Ey"          "Es"          "Ed"          "Rwd"         "Rage"        "NP"         
# [8] "CoalCode"    "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"       
# [15] "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"       
# [22] "Ll.6"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"      
# [29] "LRP.6"       "EeconS"      "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"       
# [36] "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Ps.1"        "Ps.2"       
# [43] "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"  
# [50] "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CMPid.1"     "CMPid.2"     "CMPid.3"     "CMPid.4"    
# [57] "CMPid.5"     "CMPid.6"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "CMPper415.4" "CMPper415.5"
# [64] "CMPper415.6" "Pi"          "Mnwsp"       "Mradi"       "Mtele"       "Minte"   
de=mlogit.data(de, varying=c(11:22,24:29,35:64), choice="Va", shape="wide")#create long de:

#recode Pi into 0-1:
de$Pi[de$Pi==de$alt]=0.5
de$Pi[de$Pi!=de$alt&de$Pi!=0.5]=0
de$Pi[de$Pi==0.5]=1

#code other variables:
de$LRD=abs(de$LRR-de$LRP)#Left-Right Distance voter-party
de$time=de$Ey-1960
de$Esalt=paste0(de$Es,de$alt)

#save:
setwd("~/Dropbox/Princeton/P29 reassessing leaders effect/_data")
save(de, file = "d29.RData")


#dataset only top 3 parties:----

de=de3
de=de[de$Va %in% c(1,2,3),-which(names(de) %in% c("Pl.4","Pl.5","Pl.6","Ll.4","Ll.5","Ll.6"
        ,"LRP.4","LRP.5","LRP.6","Pv.4","Pv.5","Pv.6","Ps.4","Ps.5","Ps.6"
        ,"CMPrile.4","CMPrile.5","CMPrile.6"
        ,"CMPid.4","CMPid.5","CMPid.6","CMPper415.4","CMPper415.5","CMPper415.6"))]
names(de)
```

```
##  [1] "Ec"          "Ey"          "Es"          "Ed"          "Rwd"         "Rage"        "NP"          "CoalCode"    "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Ll.1"        "Ll.2"        "Ll.3"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "EeconS"      "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"        "Pv.2"        "Pv.3"        "Ps.1"        "Ps.2"        "Ps.3"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPid.1"     "CMPid.2"     "CMPid.3"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "Pi"          "Mnwsp"       "Mradi"       "Mtele"       "Minte"
```

``` r
# [1] "Ec"          "Ey"          "Es"          "Ed"          "Rwd"         "Rage"        "NP"         
# [8] "CoalCode"    "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Ll.1"       
# [15] "Ll.2"        "Ll.3"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "EeconS"     
# [22] "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"        "Pv.2"        "Pv.3"       
# [29] "Ps.1"        "Ps.2"        "Ps.3"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPid.1"    
# [36] "CMPid.2"     "CMPid.3"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "Pi"          "Mnwsp"      
# [43] "Mradi"       "Mtele"       "Minte" 
de=mlogit.data(de, varying=c(11:16,18:20,26:40), choice="Va", shape="wide")#create long de:
#code other variables:
de$LRD=abs(de$LRR-de$LRP)#Left-Right Distance voter-party
de$time=de$Ey-1960
de$Esalt=paste0(de$Es,de$alt)
#save:
setwd("~/Dropbox/Princeton/P29 reassessing leaders effect/_data")
save(de, file = "d29_NP3.RData")
```

